我有以下功能:
CREATE OR REPLACE FUNCTION GetVarchar2 (iclCLOB IN Nvarchar2)
return NVARCHAR2
IS
cnuMAX_LENGTH Constant number := 32767 ;
nuLength Number := DBMS_LOB.getlength(iclCLOB);
sbBuffer Nvarchar2(32767);
begin
dbms_lob.read(iclCLOB,nuLength,1,sbBuffer);
return sbBuffer;
END;
当我这样称呼它时:
select GetVarChar2(text) from posts where postid = 'anId';
我收到此错误:
ORA-22835:对于 CLOB 到 CHAR 或 BLOB 到 RAW 转换的缓冲区太小(实际:6058,最大值:2000)
22835. 00000 -“缓冲区太小,无法将 CLOB 到 CHAR 或 BLOB 到 RAW 转换(实际:%s,最大值: %s)"
*原因:尝试将 CLOB 转换为 CHAR 或将 BLOB 转换为 RAW,其中
LOB 大小大于 CHAR 和 RAW
类型的缓冲区限制。
请注意,如果字符长度语义对列有效,则以字符为单位报告宽度,否则以字节为单位报告宽度。
*操作:执行以下操作之一
1. 在执行转换之前使 LOB 变小,
例如,通过在 CLOB 上使用 SUBSTR
2. 使用 DBMS_LOB.SUBSTR 将 CLOB 转换为 CHAR 或 BLOB 转换为 RAW。
问题是 NCLOB 类型的帖子表中的文本大小为 6059 字节。这很奇怪,因为当我在不调用函数的情况下执行此操作时,它运行良好。即当我运行以下脚本时:
declare
iclCLOB nvarchar2(6100) := 'Here is the same 6059 bytes string';
cnuMAX_LENGTH number := 32767 ;
nuLength Number := DBMS_LOB.getlength(iclCLOB);
sbBuffer Nvarchar2(32767);
sbBuffer1 Nvarchar2(32767);
begin
dbms_lob.read(iclCLOB,nuLength,1,sbBuffer);
select GetVarChar2(text) into sbBuffer1 from posts where postid = 'anId';
end;
它运行没有任何问题。
谢谢你。