【发布时间】:2019-03-26 17:12:57
【问题描述】:
我在 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 中创建了第二个级别 重要提示:在这种情况下,: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..."
}
【问题讨论】:
-
ords 支持返回的 LOB,将源类型设置为媒体资源,将 mime 类型设置为 application/base64 - 类似于 thatjeffsmith.com/archive/2017/09/ords-returning-raw-json
-
您好,好的,但是在这种情况下,我需要返回一个“application/json”mime 类型,并且一个字段的内容将是 base64 字符串....有什么想法吗?谢谢!
-
自己生成json
-
是的,就是这样......我正在自己编写 Json 及其工作。谢谢!
标签: plsql oracle-ords