2

I have this varchar2(2000) string:

id=100\nid2=0\nid3=0\dtext='more Text'

and I want to get only the values e.g. more Text or 0 (id3).

I was trying to use a customized SPLIT function, where separator is \n but this only returns me for example id3=0 (in this case I need '0' as result).

How can I do this more efficient?

2 Answers 2

2

and I want to get only the values e.g. more Text.

Simply use SUBSTR and INSTR

SQL> WITH DATA AS
  2    ( SELECT q'[id=100\nid2=0\nid3=0\dtext='more Text']' str FROM dual
  3    )
  4  SELECT SUBSTR(str,instr(str, '''')+1,LENGTH(SUBSTR(str,instr(str, '''')))-2) str
  5  FROM DATA
  6  /

STR
---------
more Text

SQL>
Sign up to request clarification or add additional context in comments.

4 Comments

Your solution means, I have to count for each occurence to get the right content, right?
But how to get the content for id3 for example?
In my solution, I considered the text between the single quotes.
Do you mean you need all the values immediately after = sign?
1

You could get all the values with something like this:

WITH DATA AS
  (SELECT q'[id=100\nid2=0\nid3=0\ndtext='more Text']' str FROM dual)      
SELECT replace(substr(regexp_substr(str,'(=.+?\n)|(=.+?$)',1,level),2),'\n') v    
FROM DATA
CONNECT BY LEVEL <= LENGTH(regexp_replace(str,'([^=]+=.+?\n)|([^=]=.+?$)'))

1 Comment

Wow, thats amazing. I need to have a look for those RegEx. How to get rid of the quotes e.g. 'more Text'

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.