当先锋百科网

首页 1 2 3 4 5 6 7

写了一个函数,返回一个长字符串,返回类型一开始定义为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 编辑]