欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

oracle 字符串转成行

程序员文章站 2022-05-09 14:17:55
...

oracle 将以逗号隔开的字符串'85,86,87' 转成行

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 WHERE T.cnt >= 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 WHERE C.LV oracle 字符串转成行

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。