ORACLE通过SQL将一行数据转换为多行

转换前和需要转成的格式如下图:

sql语句如下:

SELECT YJKEY, REGEXP_SUBSTR(ADDUSERCD, '[^,]+', 1, LEVEL, 'i') AS ADDUSERCD FROM (SELECT 100000004018 AS YJKEY, '1,2,3' AS ADDUSERCD FROM DUAL) T CONNECT BY LEVEL <= LENGTH(ADDUSERCD) - LENGTH(REGEXP_REPLACE(ADDUSERCD, ',', '')) + 1;

效果如下:

posted @ 2019-04-17 10:35  岁月淡忘了谁  阅读(2610)  评论(0编辑  收藏  举报