oracle字符串转成⾏
SELECT  SUBSTR (T.RPT_ID,
INSTR (T.RPT_ID,',',1,C.LV)+ 1,oracle 字符串转数组
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 <= LENGTH('85,86,87' || ',') - NVL(LENGTH(REPLACE('85,86,87', ',')), 0)) c
WHERE  Tt >= c.lv
说明:CNT表⽰串⾥⾯有多少字符。
当是字符串是表中的字段时,取level<=最⼤个数
如:
1).取最⼤个数
SELECT MAX(LENGTH(RPT_ID || ',') -
NVL(LENGTH(REPLACE(RPT_ID, ',')), 0)) INTO v_c
FROM DIM_AUDIT_TABLE@sjmh_inter;
2).l转成⾏
SELECT T.T_NAME,
T.T_NAME_COMM,
T.T_COLUMN,
T.T_COLUMN_COMM,
t.COMMENT_NL,
t.COMMENT_NL_TIME,
t.SEQ_USER_ID,
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 A.T_NAME,
A.T_NAME_COMM,
A.T_COLUMN,
A.T_COLUMN_COMM,
a.COMMENT_NL,
a.COMMENT_NL_TIME,
a.SEQ_USER_ID,
'','' || A.RPT_ID || '','' RPT_ID,
LENGTH(A.RPT_ID || '','') -
NVL(LENGTH(REPLACE(A.RPT_ID, '','')), 0) CNT
FROM DIM_AUDIT_TABLE@sjmh_inter A
WHERE a.COMMENT_NL is not null) T,
(SELECT LEVEL LV FROM DUAL CONNECT BY LEVEL <= '||v_c||') C
WHERE C.LV <= T.CNT;
注:如果是上⾯代码是远程的代码,(SELECT LEVEL LV FROM DUAL CONNECT BY LEVEL <= '||v_c||') C,不要⽤dual表,可以改⽤all_objects或user_objects, 要不然能查询,但是把查询出来的SQL插⼊到某个表时,只能插⼊⼀⾏

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。