日期:2014-05-17 浏览次数:20882 次
select regexp_substr('DEPT_BMLD_BSTAZM00', '[^_]+', 1, level) from dual connect by level <= length(regexp_replace('DEPT_BMLD_BSTAZM00', '[^_]+', null))+1
------解决方案--------------------
SELECT SUBSTR('DEPT_BMLD_BSTAZM00',INSTR('DEPT_BMLD_BSTAZM00','_',1,1)+1, INSTR('DEPT_BMLD_BSTAZM00','_',1,2)-INSTR('DEPT_BMLD_BSTAZM00','_',1,1)-1 ) , SUBSTR('DEPT_BMLD_BSTAZM00',INSTR('DEPT_BMLD_BSTAZM00','_',1,2)+1 ) FROM DUAL
------解决方案--------------------
如果只有两个下划线,可以用这个写法,应该是通用的。
SELECT SUBSTR(item,1,instr(item,'_') -1) AS fst,
SUBSTR(item,instr(item,'_') + 1,instr(item,'_',instr(item,'_') + 1) - instr(item,'_') - 1 ) AS scd /*instr的特殊用法,指定起始位置instr(item,'_',从第一个下划线后一个位置开始)*/
FROM
( SELECT 'aaa_bbb_ccc' AS item FROM dual
UNION ALL
SELECT 'dd_ee_ff' AS item FROM dual
)
--结果
FST SCD
----------- -----------
aaa bbb
dd ee
------解决方案--------------------