0

I'm going to distinguish values and make them columns through a string column. my string format is as below :

||1|21|-1|-1|-1|0||||

I already have tried to using instr or regexp_instr but as in some rows the first character is null ,it returns wrong data.here the separator is '|' .

enter image description here

It's appreciated if you could help me into this issue.

1
  • anybody can help? Commented Jan 30, 2017 at 9:12

1 Answer 1

1

Query:

WITH sample_data ( "COMMENT" ) AS (
  SELECT '||1|21|-1|-1|-1|0||||' FROM DUAL
)
SELECT REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 1, NULL, 1 ) AS col1,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 2, NULL, 1 ) AS col2,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 3, NULL, 1 ) AS col3,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 4, NULL, 1 ) AS col4,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 5, NULL, 1 ) AS col5,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 6, NULL, 1 ) AS col6,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 7, NULL, 1 ) AS col7,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 8, NULL, 1 ) AS col8,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 9, NULL, 1 ) AS col9,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 10, NULL, 1 ) AS col10,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 11, NULL, 1 ) AS col11,
       REGEXP_SUBSTR( "COMMENT", '(.*?)(\||$)', 1, 12, NULL, 1 ) AS col12
FROM   sample_data;

Output:

COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 COL12
---- ---- ---- ---- ---- ---- ---- ---- ---- ----- ----- -----
          1    21   -1   -1   -1   0
Sign up to request clarification or add additional context in comments.

2 Comments

many thanks and appreciations ,it works as well .best regards
anybody can help me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.