当前位置: 数据库>oracle
oracle 字符串转成行
来源: 互联网 发布时间:2014-09-07
本文导语: SELECT SUBSTR (T.RPT_ID, INSTR (T.RPT_ID,',',1,C.LV)+ 1, INSTR (T.RPT_ID,',',1,C.LV + 1)- (INSTR (T.RPT_ID,',',1,C.LV)+ 1)) AS RPT_ID FROM (SELECT ',' || '85,86,87' || ',' RPT_ID, ...
SELECT SUBSTR (T.RPT_ID,
INSTR (T.RPT_ID,',',1,C.LV)+ 1,
INSTR (T.RPT_ID,',',1,C.LV + 1)- (INSTR (T.RPT_ID,',',1,C.LV)+ 1))
AS RPT_ID
FROM (SELECT ',' || '85,86,87' || ',' RPT_ID,
LENGTH ('85,86,87' || ',') - NVL (LENGTH (REPLACE ('85,86', ',')), 0) CNT
FROM DUAL) t,
(SELECT LEVEL lv
FROM DUAL
CONNECT BY LEVEL = c.lv
说明:CNT表示串里面有多少字符。
当是字符串是表中的字段时,取level
INSTR (T.RPT_ID,',',1,C.LV)+ 1,
INSTR (T.RPT_ID,',',1,C.LV + 1)- (INSTR (T.RPT_ID,',',1,C.LV)+ 1))
AS RPT_ID
FROM (SELECT ',' || '85,86,87' || ',' RPT_ID,
LENGTH ('85,86,87' || ',') - NVL (LENGTH (REPLACE ('85,86', ',')), 0) CNT
FROM DUAL) t,
(SELECT LEVEL lv
FROM DUAL
CONNECT BY LEVEL = c.lv
说明:CNT表示串里面有多少字符。
当是字符串是表中的字段时,取level