decode substr 片段判断选取功能的实现
一行字符串 如ABC00123
AEF00987
BHDBU9IO
45I00KIJ
12345678
如何实现 判断滴4 5 为为00的时候 只读取ABC 当不是00的时候字符串全部读取 BHDBU9IO
decode(substr(pk.shipmentnumber,4,5),'00',substr(pk.shipmentnumber,1,3)) A,
SUBSTR (pk.shipmentnumber, 6, LENGTH (pk.shipmentnumber)) B,
最后查询结果如下面
A | B
ABC 123
AEF 987
BHDBU 9IO
45I KIJ
12345 678
请帮忙写该或给出 正确的选取判断语句 谢谢
------解决方案-------------------- with t as
(select 'ABC00123' str
from dual
union all
select 'AEF00987'
from dual
union all
select 'BHDBU9IO'
from dual
union all
select '45I00KIJ'
from dual
union all
select '12345678' from dual)
select replace(substr(str, 1, 5), '00', '') a, substr(str, -3) b from t;
------解决方案-------------------- 引用: with t as
(select 'ABC00123' str
from dual
union all
select 'AEF00987'
from dual
union all
select 'BHDBU9IO'
from dual
union all
select '45I00KIJ'
from dual
union all
select '12345678' from dual)
select replace(substr(str, 1, 5), '00', '') a, substr(str, -3) b from t;
同意。。。
------解决方案-------------------- 引用: decode(substr(pk.shipmentnumber,4,5),'00',substr(pk.shipmentnumber,1,3), pk.shipmentnumber)
decode(substr(pk.shipmentnumber,4,2),'00',substr(pk.shipmentnumber,1,3), pk.shipmentnumber)