create table t ( x int, y clob );
create or replace procedure p( p_x in int, p_new_text in varchar2 )
as
begin
insert into t values ( p_x, p_new_text );
end;
/
exec p(1, rpad('*',4002,'*') );
exec p(2, rpad('é',4002,'é') );
select x, dbms_lob.getlength(y) from t;
select x, dbms_lob.substr(y,4000,1) from t where x = 1; -- this one does not give error and function correctly finds 4000 characters as each character 1 byte
select x, dbms_lob.substr(y,4000,1) from t where x = 2; -- function not able to find 4000 characters and gives error as é is more than 1 byte.
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1
问题是当 clob 字段中可能有一些字符占用超过 1 个字节时,如何从 oracle 中找到 4000 个字符。