今天一开发员提交了这样的问题,他的代码执行时,碰到如下的错误:
...
32767:32767
32768:32768
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 9
SQL> l
1 declare
2 v_doc CLOB;
3 c char(1);
4 i NUMBER;
5 begin
6 i := 0;
7 c :='1';
8 for i in 1..100000 loop
9 v_doc := v_doc || '' || 1;
10 dbms_output.put_line('' || i || ':' || dbms_lob.getlength(v_doc));
11 end loop;
12* end;
SQL>
从上面的执行结果来看,错误执行到32769轮回时出错,出错的时候,CLOB的长度32768.CLOB不可能只存储这么点数据的。把代码行:v_doc := v_doc || '' || 1改成:v_doc := v_doc || '' ||'1',把这行代码里的数字1前后加上单引号,代码能正常执行了。但奇怪的是,前面的32768次循环中,如果把v_doc当成数字来处理也不可能的。
这个是什么引起的呢,从报的错误来看...,找不到原因.
[@more@]关于这个问题,今天(11月16)得到oracle的证实,这是一个bug,但补丁没有出来.
Bug 5583729 : CONCATENATION OF CLOB AND NUMBER ORA-6502
Bug 6774987 : ORA-6502 CONCATENATING NUMBER TO LARGE STRINGS CLOB DATATYPE VARIABLES
解决方法就是,显示转换后面的数字.
1. Use the TO_CHAR function to explicitly convert the number to a varchar2 value
declare
v_doc CLOB;
i NUMBER;
begin
i := 0;
for i in 1..100000 loop
v_doc := v_doc || '' ||to_char(1);
end if;
dbms_output.put_line('' || i || ':' || dbms_lob.getlength(v_doc));
end loop;
end;
/
2. Use dbms_lob.writeappend
declare
v_doc CLOB;
l_append_to_clob VARCHAR2(1024) := 1;
begin
v_doc := ' ';
for i in 1..100000 loop
dbms_lob.writeappend(v_doc,length(l_append_to_clob), l_append_to_clob);
end loop;
end;
/
There is a database limit which only allows at the most 32767 characters to be written at one time for CLOB datatypes.Any data greater than that size will have to be written in chunks. Note: 358641.1 describes this limitation.CLOB datatype is limited to 32767. Anything above it will result in ORA-06512 error.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/45188/viewspace-1028678/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/45188/viewspace-1028678/