我正在Oracle ORDS中创建一个Rest API,我需要返回一个大于32k的base64文本。源类型是PL / SQL。
原始数据位于CLOB变量中,但ORDS不支持此类返回。我尝试使用LONG,但是当它大于32k时我无法将字符串移动到LONG。
--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..."
}
无法找到自动完成的方法,所以我自己写了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('"}');