0

I have a json array string like below

[{a:100},{a:200},{a:300},{a:400}]

Passing it as a CLOB input parameter to the Stored procedure

How can i get a tabular output like below with in sql so that i can bulk insert in a table

Value
-----------
100
200
300
400

I have tried some examples mentioned at oracle docs but unable to find the working example with above mentioned output.

Thanks

1 Answer 1

1

Use a JSON_TABLE:

Oracle Setup:

CREATE TABLE destination ( a NUMBER );

PL/SQL:

DECLARE
  your_input_parameter CLOB := '[{a:100},{a:200},{a:300},{a:400}]';
BEGIN
  INSERT INTO destination ( a )
    SELECT a
    FROM   JSON_TABLE(
             your_input_parameter,
             '$[*]'
             COLUMNS a NUMBER PATH '$.a'
           );
END;
/

Output:

SELECT * FROM destination;
|   A |
| --: |
| 100 |
| 200 |
| 300 |
| 400 |

db<>fiddle here

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

Comments

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.