在 Oracle 19c 中将大 json 返回到 clob 时出现 ORA-40478
ORA-40478 when returning large json into clob in Oracle 19c
在 Oracle 19c 中我创建了 table:
create table SAMPLE_TABLE (
id NUMBER not null,
display_name NVARCHAR2(4000), )
当我运行脚本时:
declare
i integer;
p_tmp_clob clob;
begin
select JSON_ARRAYAGG(JSON_OBJECT(t.* )) into p_tmp_clob from SAMPLE_TABLE t;
end;
我收到以下 ORA-40478 异常。
ORA-40478: 输出值太大(最大值:4000)
The character string returned by this function is of data type
VARCHAR2. This clause allows you to specify the size of the VARCHAR2
data type. Use BYTE to specify the size as a number of bytes or CHAR
to specify the size as a number of characters. The default is BYTE. If
you omit this clause, or if you specify this clause but omit the size
value, then JSON_OBJECT returns a character string of type
VARCHAR2(4000).
您需要将函数告诉 return a CLOB,而不是 varchar:
JSON_ARRAYAGG 可能也需要(或者可能只有那里 - 我现在无法测试)
declare
i integer;
p_tmp_clob clob;
begin
select JSON_ARRAYAGG(JSON_OBJECT(t.* RETURNING CLOB) RETURNING CLOB)
into p_tmp_clob
from SAMPLE_TABLE t;
end;
在 Oracle 19c 中我创建了 table:
create table SAMPLE_TABLE (
id NUMBER not null,
display_name NVARCHAR2(4000), )
当我运行脚本时:
declare
i integer;
p_tmp_clob clob;
begin
select JSON_ARRAYAGG(JSON_OBJECT(t.* )) into p_tmp_clob from SAMPLE_TABLE t;
end;
我收到以下 ORA-40478 异常。 ORA-40478: 输出值太大(最大值:4000)
The character string returned by this function is of data type VARCHAR2. This clause allows you to specify the size of the VARCHAR2 data type. Use BYTE to specify the size as a number of bytes or CHAR to specify the size as a number of characters. The default is BYTE. If you omit this clause, or if you specify this clause but omit the size value, then JSON_OBJECT returns a character string of type VARCHAR2(4000).
您需要将函数告诉 return a CLOB,而不是 varchar:
JSON_ARRAYAGG 可能也需要(或者可能只有那里 - 我现在无法测试)
declare
i integer;
p_tmp_clob clob;
begin
select JSON_ARRAYAGG(JSON_OBJECT(t.* RETURNING CLOB) RETURNING CLOB)
into p_tmp_clob
from SAMPLE_TABLE t;
end;