如何使用JSON(超过32k)在ORDS中返回大文本

问题描述 投票:1回答:1

我正在Oracle ORDS中创建一个Rest API,我需要返回一个大于32k的base64文本。源类型是PL / SQL。

原始数据位于CLOB变量中,但ORDS不支持此类返回。我尝试使用LONG,但是当它大于32k时我无法将字符串移动到LONG。

  • 我试图将内容从CLOB移到LONG,但没有成功。
  • 我尝试使用我需要的文本创建两个Long变量,并将其连接到Long变量以输出它,但也没有成功。
  • 我能够在ResultSet中返回内容,但它会使Json结构与我需要的不同。
--This is the variable that has the large text (about 40k characters)
out_hexa        CLOB;

- :boleto是ORDS中的OUT参数(OUT,RESPONSE,LONG)

--This wont work:
:boleto := out_hexa;
--This wont work:
:boleto := substr(out_hexa, 1, 32765) || substr(out_hexa, 32765, LENGTH(out_hexa));

- 这是有效的,但是Json输出不是我想要的方式,因为它在Json Importante中创建了第二级:在这种情况下,:boleto是一个ResultSet,而不是一个Long

OPEN :boleto FOR
     SELECT out_hexa as dados from dual;
In this case the output is:
{
    "boleto": [
        {
            "dados": "JVBERi0xLjQKMSAwIG9iago8PAovVGl0bGUgKP7..."
        }
     ]
}


What I need is a Json in this format:
{
    "boleto": "JVBERi0xLjQKMSAwIG9iago8PAovVGl0bGUgKP7..."
}
plsql oracle-ords
1个回答
1
投票

无法找到自动完成的方法,所以我自己写了Json。我正在以块的形式读取CLOB并使用HTP.prn编写它:

      OWA_UTIL.mime_header('application/json', FALSE);
      OWA_UTIL.http_header_close;         
      htp.prn('{');
      htp.prn('"return_code" : "' ||out_status || '",');
      htp.prn('"return_message" : "' ||out_msg_retorno || '",');
      htp.prn('"boleto" : "');

      IF(out_status = '001') THEN
        :http_status      := 200;                    
        WHILE counter < length(out_hexa)+chunk_size LOOP                     
            htp.prn(substr(out_hexa, counter, chunk_size));
            counter := counter+chunk_size;
        END LOOP;        
      ELSE
        :http_status      := 404;
      END IF;
      htp.prn('"}');
© www.soinside.com 2019 - 2024. All rights reserved.