I have one JSON file and I´m trying to insert in database.
Inserts are not working, not sure if I am looping correctly json
I´ve done a very easy example:
This is the table:
CREATE TABLE TEST (
remote_claimid VARCHAR2(20) PRIMARY KEY
);
and the procedure:
PROCEDURE TEST (
p_json CLOB
) AS
BEGIN
INSERT INTO TEST (
remote_claimid
)
SELECT
remote_claimid
FROM JSON_TABLE(
p_json,
'$.claim[*]'
COLUMNS(
remote_claimid VARCHAR2(20) PATH '$.remote_claimid'
)
);
COMMIT;
exception when others then
log_api.fatal(log_ctx, 'ERROR INSERT_TEST');
raise;
END TEST;
And this is the JSON
{claim=[{remote_claimid=5680}, {remote_claimid=7654}]}
This is the call:
json = '{"claim"=[{"remote_claimid"="5680"}, {"remote_claimid"="7654"}]}'
try {
sql.call('{call BILLING_API.TEST(?)}', [json])
output = [SUCCESS: true, msg: "inserts added."]
sql.commit()
} catch(SQLException se) {
sql.rollback()
log.error("Exception: ${se}; Procedure: BILLING_API.TEST; Params: Clob ${responseList}")
output = commonDBService.processException(se)
} finally {
sql.close()
}
Nothing is inserted, no errors… nothing
Any idea what´s happening?
Thanks!
2
Answers
With correct JSON your path works:
I could not find any issue in your code. But i will suggest , Can you try like this. I think this is the better way to insert json into the oracle db.
Hope this code helps you.