У меня есть следующие функции:Oracle 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
Вы правы. Это была ошибка с копией. – Shayan