ho creato il seguente script per leggere i dati da Mobile App DB (che si basa su MongoDB) da Oracle SQL Developer:Parse JSON nella tabella di Oracle utilizzando PL/SQL
DECLARE l_param_list VARCHAR2(512); l_http_request UTL_HTTP.req; l_http_response UTL_HTTP.resp; l_response_text VARCHAR2(32767); BEGIN -- service's input parameters -- preparing Request... l_http_request := UTL_HTTP.begin_request ('https://api.appery.io/rest/1/db/collections/Photos?where=%7B%22Oracle_Flag%22%3A%22Y%22%7D' , 'GET' , 'HTTP/1.1'); -- ...set header's attributes UTL_HTTP.set_header(l_http_request, 'X-Appery-Database-Id', '53f2dac5e4b02cca64021dbe'); --UTL_HTTP.set_header(l_http_request, 'Content-Length', LENGTH(l_param_list)); -- ...set input parameters -- UTL_HTTP.write_text(l_http_request, l_param_list); -- get Response and obtain received value l_http_response := UTL_HTTP.get_response(l_http_request); UTL_HTTP.read_text(l_http_response, l_response_text); DBMS_OUTPUT.put_line(l_response_text); insert into appery values(l_response_text); -- finalizing UTL_HTTP.end_response(l_http_response); EXCEPTION WHEN UTL_HTTP.end_of_body THEN UTL_HTTP.end_response(l_http_response); END; /
La risposta (l_response_text) è una stringa simile a JSON. Ad esempio:
[{"Postcode":"47100","OutletCode":"128039251","MobileNumber":"","_createdAt":"2014-11-10 06:12:49.837","_updatedAt":"2014-11-10 06:12:49.837"}, {"Postcode":"32100","OutletCode":"118034251", ..... ]
Il codice funziona bene, e inserisce la risposta in una colonna tavolo chiamato appery. Tuttavia, ho bisogno di analizzare questa risposta in modo tale che ogni array entri nella sua specifica colonna in una tabella chiamata appery_test. La tabella appery_test ha un numero di colonne uguale al numero di coppie JSON e nello stesso ordine.
Ho cercato e ho trovato la maggior parte dei risultati sull'analisi del tavolo Oracle in JSON e non il contrario. Ho trovato, però, il collegamento this che è in qualche modo simile al mio problema. Tuttavia, la libreria suggerita nella risposta non ha alcun esempio su come usarla per inserire JSON nella tabella convenzionale usando PL/SQL.
N.B .: Sto usando 11g e non 12c. Quindi le funzioni built in non sono disponibili per me.
E 'disponibile solo affermando da Oracle v1.12. Nota di rilascio: https: // oracle-base.com/articles/12C/PLSQL-oggetto-tipi-per-JSON-12cr2 – gavenkoa