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..."
}
4

1 回答 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('"}');
于 2019-03-27T16:32:28.793 回答