Store big JSON files into Oracle DB

前端 未结 2 1244
情书的邮戳
情书的邮戳 2020-12-20 00:00

I\'m using the following script in order to read data from MongoDB as JSON files.

DECLARE
  l_param_list     VARCHAR2(512);
 
  l_http_request   UTL_HTTP.req;         


        
2条回答
  •  無奈伤痛
    2020-12-20 00:20

    Your problem is in your call to UTL_HTTP.read_text. You are passing a CLOB, but read_text only accepts VARCHAR2, so it can return a maximum of 32k bytes.

    You need to call it in a loop, using a VARCHAR2 buffer, and concatenate the results into your CLOB, e.g.:

    DECLARE
      buf VARCHAR2(32767);
    BEGIN
      LOOP
        UTL_HTTP.read_text(l_http_response, buf);
        l_response_text := l_response_text || buf;
      END LOOP;
    EXCEPTION
      WHEN UTL_HTTP.end_of_body THEN
        NULL;
    END;
    

    http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/u_http.htm#ARPLS71074

    Your second problem is that json_ext.get_string only returns a VARCHAR2, which means it is limited to 32767 byes max. I've had a browse of the PL/json wiki, you might need to reach out to one of the authors to find out how to use it to get a CLOB value.

提交回复
热议问题