如何将逗号分隔的值转换为记录?

时间:2019-04-15 06:34:22

标签: sql oracle

在Oracle SQL中,我有一组字符串,例如...

Select 'AX', 'BC' from dual;

我需要这些字符串作为单独的记录,如下所示。

必需的输出:

Column1
---------------
AX

BC

3 个答案:

答案 0 :(得分:2)

在Oracle中,您可以尝试

with mydata as 
     (select q'[AX,BC]' mycol from dual)
       select regexp_substr(mycol, '[^,]+', 1, level) result from mydata
       connect by level <= length(regexp_replace(mycol, '[^,]+')) + 1; 

答案 1 :(得分:2)

一种方式就是这样

with t as (Select 'AX' col1, 'BC' col2 from dual)
select col1 from t
union 
select col2 from t

答案 2 :(得分:2)

请检查以下代码。希望这有助于您达成目标。

with table1 as
 (Select 'AX,BC' as data1 from dual)

SELECT REGEXP_SUBSTR(data1, '[^,]+', 1, LEVEL) TXT
  FROM table1
CONNECT BY level <= length(regexp_replace(data1, '[^,]+')) + 1;