简体   繁体   中英

Parse Json Response and insert into oracle

I am new to oracle and facing a little challenge in iterating through a json response. I know there are many examples online which work on json array element and then insert, but i tried various things and couldnt get this to work.

The json response is like this:

{
    'data':
         {
           'Key_one' : 'value_one',
           'Key_two' : 'value_two'
         }
}

I have a stored proc:

CREATE OR REPLACE PROCEDURE TEST(JSON_TEXT_DATA) AS
BEGIN
---- need a for loop here to dynamically iterate and insert. 
INSERT INTO TABLE_NAME('KEY_ONE') values(json_value(JSON_TEXT_DATA,'$.data.Key_One'));
INSERT INTO TABLE_NAME('KEY_TWO') values(json_value(JSON_TEXT_DATA,'$.data.Key_Two'));
END;

You can try using JSON_TABLE to insert the values into your table. Using this method will put both keys into a single row in your table.

INSERT INTO table_name (key_one, key_two)
    SELECT key1, key2
      FROM JSON_TABLE ('{
    "data":
         {
           "Key_one" : "value_one",
           "Key_two" : "value_two"
         }
}',
                       '$.data'
                       COLUMNS key1 VARCHAR2 PATH '$.Key_one', key2 VARCHAR2 PATH '$.Key_two');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM