我在Oracle中有一个列,其中字符串以011开头,一些字符串是完美的,我不想删除。 通过使用此Oracle查询,我得到了这个结果
select termnum, substr(termnum,4) as New_TermNum from reject
Termnum New_Termnum
011390864324465 390864324465
011390465772400 390465772400
0117845300123 7845300123
6306900110 6900110
7893465126 3465126
我希望像这样拥有New_Termnum专栏
Termnum New_Termnum
011390864324465 390864324465
011390465772400 390465772400
0117845300123 7845300123
6306900110 6306900110
7893465126 7893465126
感谢您提前获得帮助
答案 0 :(得分:1)
当且仅当字符串以011
011
select (case when substr(termnum,1,3) = '011'
then substr(termnum,4)
else termnum
end) as newTermNum
from reject
答案 1 :(得分:1)
您可以REGEXP_REPLACE
使用CASE
或SUBSTR
:
SELECT termnum,
REGEXP_REPLACE( termnum, '^011' ) AS new_termnum,
CASE SUBSTR( termnum, 1, 3 )
WHEN '011' THEN SUBSTR( termnum, 4 )
ELSE termnum
END AS new_termnum2
FROM reject;
<强>输出强>:
TERMNUM NEW_TERMNUM NEW_TERMNUM2
--------------- --------------- ---------------
011390864324465 390864324465 390864324465
011390465772400 390465772400 390465772400
0117845300123 7845300123 7845300123
6306900110 6306900110 6306900110
7893465126 7893465126 7893465126