根据列中的逗号拆分列值

时间:2019-05-16 11:41:22

标签: sql oracle

我有一个名为Test的表,具有以下值

ID Name Description
1  Xyz   Mumbai,Delhi

我想要Sql查询,它将给出如下输出

ID Name Description
1  Xyz   Mumbai
1  Xyz   Delhi

1 个答案:

答案 0 :(得分:0)

您可以将regexp_substr'[^,]+'模式一起用作第二个参数,以分隔逗号分隔的字符串

with tab( ID, Name, Description ) as
(
 select 1,'Xyz','Mumbai,Delhi' from dual
)
select ID, Name, 
       regexp_substr(Description,'[^,]+',1,level)
       as Description
  from tab 
 connect by level <= regexp_count(Description,',')+1;

ID  NAME   DESCRIPTION
--  ----   -----------
1   Xyz    Mumbai
1   Xyz    Delhi