oracle将以逗号分隔字符串转多行

不做详解,直接上图。

SELECT T.NAME, T.TESTSTR FROM TEST2 T;

oracle将以逗号分隔字符串转多行_第1张图片 

SELECT DISTINCT T.NAME,
       REPLACE(REGEXP_SUBSTR(T.TESTSTR, '[^,]+', 1, LEVEL), ',', ' ') TESTSTR
FROM TEST2 T  
WHERE 1 = 1 
      CONNECT BY LEVEL <= (LENGTH(T.TESTSTR) - LENGTH(REPLACE(T.TESTSTR, ',', '')) + 1);

oracle将以逗号分隔字符串转多行_第2张图片

-- Create table TEST2
create table TEST2
(
  id      NUMBER(10),
  name    VARCHAR2(100),
  teststr VARCHAR2(100)
)

insert into TEST2 (ID, NAME, TESTSTR)
values (2, '徐风年', '洛阳,贾家嘉,姜姒,鱼幼薇,裴南苇,红薯');

insert into TEST2 (ID, NAME, TESTSTR)
values (1, '李淳罡', '剑开天门,两袖青蛇,绿袍儿,剑来');

insert into TEST2 (ID, NAME, TESTSTR)
values (3, '武器', '绣冬,春雷,玄甲,青梅,竹马,朝露,春水,桃花,峨眉,朱雀,黄桐,蚍蜉,金缕,太阿');

insert into TEST2 (ID, NAME, TESTSTR)
values (4, '温华', '不胜,折剑出江湖');

你可能感兴趣的:(Oracle数据库)