我有以下功能:甲骨文NCLOB问题
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: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6058, maximum: 2000)
22835. 00000 - "Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: %s, maximum: %s)"
*Cause: An attempt was made to convert CLOB to CHAR or BLOB to RAW, where
the LOB size was bigger than the buffer limit for CHAR and RAW
types.
Note that widths are reported in characters if character length semantics are in effect for the column, otherwise widths are reported in bytes.
*Action: Do one of the following
1. Make the LOB smaller before performing the conversion,
for example, by using SUBSTR on CLOB
2. Use DBMS_LOB.SUBSTR to convert CLOB to CHAR or BLOB to 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;
它运行没有任何问题。
谢谢。
我不认为你的最后一个例子没有问题。它必须是SELECT ... INTO,否? – DCookie 2010-07-26 16:28:06
你是对的。这是一个复制粘贴错误。 – Shayan 2010-07-26 20:03:51