0

I need to split a row into multiple rows.

sample value in a column is like this.

Message for status: warnings: [w1,w2] | errors: [e1,e2] | other_errors: [e3]

Above total message is in one column value. I need to split it multiple rows like

w1
w2
e1
e2
e3
  • Can some one help me how to do this?
AlvaroAV
  • 10,335
  • 12
  • 60
  • 91
Mahesh
  • 99
  • 1
  • 5

1 Answers1

0

Here's one method for splitting into columns:

select
  ltrim(regexp_substr(translate(col1,'[]',',,'),',([^,]+)', 1,1) ,',') s1,
  ltrim(regexp_substr(translate(col1,'[]',',,'),',([^,]+)', 1,2) ,',') s2,
  ltrim(regexp_substr(translate(col1,'[]',',,'),',([^,]+)', 1,4) ,',') s3,
  ltrim(regexp_substr(translate(col1,'[]',',,'),',([^,]+)', 1,5) ,',') s4,
  ltrim(regexp_substr(translate(col1,'[]',',,'),',([^,]+)', 1,7) ,',') s5
from
  t1;

Then you need to unpivot it, and there are plenty of examples on SE.

David Aldridge
  • 51,479
  • 8
  • 68
  • 96