oracle报字符串缓冲区太小,请开发高手帮忙,函数返回值时,报字符串缓冲区太小!...

在Oracle 9i环境下,一个PL/SQL函数返回字符串时遇到ora-06502错误。最初定义返回类型为varchar2(32767),但发现即使字符串长度只有5000多也会报错。改为使用CLOB类型后问题依然存在。函数根据脚本ID生成试题字符串,涉及到游标和字符串拼接操作。问题可能出在字符串拼接导致的内存溢出或CLOB处理不当。
摘要由CSDN通过智能技术生成

写了一个函数,返回一个长字符串,返回类型一开始定义为varchar2(32767),但是发现有时候执行时会报错ora-06502字符串缓冲区太小的错误。查网上资料说如果返回的字符串长度超过4000就会报这个错,于是将返回值类型改成了clob,但是有时候执行的时候仍然会报错。

我在plsql中跟踪,发现返回值的长度才5000多,为啥还会报错呢。请高手指点!

Oracle9i windows系统

函数代码如下(红色那句话就是执行报错的地方):

create or replace function P_Return_QuestionScript(vScriptID in varchar2) return varchar2 is

Result clob;--varchar2(32767);

-----------------------------------------

--功能:根据脚本ID,自动生成报表用的试题字符串

--输入参数:脚本ID

--输出:试题字符串

--日期:2009-6-2

-----------------------------------------

--根据脚本ID创建问题游标

cursor mycursor is select question_id,question_code,question_type from tbl_script_question

where script_id=vScriptID and question_type in ('Single_choice','blank','Multi_choice') order by question_id;

V_QuestionID varchar2(50);

V_QuestionCode varchar2(50);

V_QuestionType varchar2(50);

i integer;

j integer;

result2 varchar2(32767);

begin

Result2 := '';

j := 0;

open mycursor;

loop

--获取问题ID和问题code

fetch mycursor into V_QuestionID,V_QuestionCode,V_QuestionType;

exit when mycursor%notfound;

i := 0;

--根据问题的类型分别进行解析

if V_QuestionType = 'blank' then

begin

--Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',a.answer_content)) 题'||V_QuestionCode||',';

Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',a.answer_content)) 题'||to_char(j)||',';

end;

else

if V_QuestionType = 'Single_choice' then

begin

--Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',o.option_value)) 题'||V_QuestionCode||',';

Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',o.option_value)) 题'||to_char(j)||',';

select count(option_id) into i from tbl_script_question_option where question_id=V_QuestionID and is_remarked='1';

if i > 0 then

begin

--Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',p_stringreplace(answer_memo))) 题'||V_QuestionCode||'_,';

Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',p_stringreplace(answer_memo))) 题'||to_char(j)||'_,';

end;

end if;

end;

else

if V_QuestionType = 'Multi_choice' then

begin

--Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',func_exchange_answer2(a.answer_content))) 题'||V_QuestionCode||',';

Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',func_exchange_answer2(a.answer_content))) 题'||to_char(j)||',';

select count(option_id) into i from tbl_script_question_option where question_id=V_QuestionID and is_remarked='1';

if i > 0 then

begin

--Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',p_stringreplace(answer_memo))) 题'||V_QuestionCode||'_,';

Result2 := Result2 || 'max(decode(q.question_code,'''||V_QuestionCode||''',p_stringreplace(answer_memo))) 题'||to_char(j)||'_,';

end;

end if;

end;

end if;

end if;

end if;

j := j + 1;

end loop;

close mycursor;

dbms_lob.createtemporary(result, true);

dbms_lob.writeappend(result, length(result2), result2);

return(result);

end P_Return_QuestionScript;

[本帖最后由 maying 于 2009-6-3 18:56 编辑]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值