0

I'm receiving from an API a JavaScript array inside a string like the following:

'["qwe","asd","zxc","345"]'

And I'm trying to get it to become a list of items, which I did.

SELECT  regexp_substr(
          REPLACE( 
            REPLACE(
              REPLACE('["qwe","asd","zxc","345"]', '"', ''),
            '[',''),
          ']',''),
        '[^,]+', 1, LEVEL) AS Lista
FROM  dual
CONNECT BY instr(REPLACE( 
            REPLACE(
              REPLACE('["qwe","asd","zxc","345"]', '"', ''),
            '[',''),
          ']','')
          , ',', 1, LEVEL - 1) > 0;

The problems is that it doesn't feel right.

Please, can someone help me to either optimize/improve the code or maybe confirm that this is it and there is nothing to be done.

Thx

1
  • 1
    With supported (modern) Oracle Versions you can use json_table() Commented Dec 9, 2019 at 14:33

1 Answer 1

1

Assuming you're on 12.1.0.2 or higher, the "correct" way to do this is with json_table

select * from json_table (
  '["qwe","asd","zxc","345"]', '$[*]'
  columns (
    val path '$'
  )
);

VAL   
qwe    
asd    
zxc    
345 
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, awesome Chris, I knew there was a better way. Thx

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.