0

In Oracle SQL, I have a set of strings like...

Select 'AX', 'BC' from dual;

I need these strings as separate records as below.

Required Output:

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

BC
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Vijesh1985
  • 49
  • 4

3 Answers3

2

In Oracle, you can try this

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; 
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Arun Palanisamy
  • 5,281
  • 6
  • 28
  • 53
2

One way would be like this

with t as (Select 'AX' col1, 'BC' col2 from dual)
select col1 from t
union 
select col2 from t
hol
  • 8,255
  • 5
  • 33
  • 59
2

Please check the below code. Hope this helps to achieve your results.

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; 
Ahamed
  • 312
  • 1
  • 8