ORA-06502: PL/SQL: numeric or value error错误解决

    当执行如下语句时出现“06502数字或值错误”,func_fa_getunororgpath函数主要是将人员组织ID参数转换为人员名称、组织PATH。
select func_fa_getunororgpath(pc.personorgselect) from tbl_pt_createtask pc where pc.orderid='2-090210-008-096'


    查看函数得知该函数返回VARCHAR2(4000)类型,函数代码如下:
create or replace function func_fa_getUNorOrgPath(idOrPath in varchar2) return string is
   Result varchar2(4000);
   urserOrOrgId varchar2(2000);
begin
   urserOrOrgId:=idOrPath;
  while urserOrOrgId is not null loop
       ……  ……
       ……  ……
      if tmpStr is null then
          Result:=Result ||tmpId ||';';
     else
          Result:=Result ||tmpStr ||';';      
     end if;       
  end loop;
  return(substr(Result,0,length(Result)-1));
end func_fa_getUNorOrgPath;

    当Result长度超过4000时,再执行Result:=Result ||tmpStr ||';';时即出现该错误,固改为返回CLOB类型,代码如下:
create or replace function func_fa_getUNorOrgPath(idOrPath in varchar2) return CLOB is
   Result CLOB;
   urserOrOrgId varchar2(2000);
   urserOrOrgId:=idOrPath;
begin
  if idOrPath is null then
     return empty_clob();  
  end if;
  DBMS_LOB.CREATETEMPORARY(Result, TRUE); 
  while urserOrOrgId is not null loop
       ……  ……
        if tmpStr is null then
            DBMS_LOB.writeappend(Result,LENGTH(tmpId),tmpId);
            DBMS_LOB.writeappend(Result,LENGTH(';'),';');
        else
            DBMS_LOB.writeappend(Result,LENGTH(tmpStr),tmpStr);
            DBMS_LOB.writeappend(Result,LENGTH(';'),';');
        end if;  
  end loop;
  return(substr(Result,0,length(Result)-1));
end func_fa_getUNorOrgPath;


    但在java中读取数据时需要采用Stream进行读取

你可能感兴趣的:(sql)