create or replace function Test04(sCustomerID varchar2,sType varchar2) 
return varchar2 is 
  Result varchar(20); 
   
  s1 varchar(20); 
  s2 varchar(20); 
  s3 varchar(20);
begin
  --下面有多个值,报错
  select CustomerID into s1 from CUSTOMER_RELATIVE
  where Relativeid=sCustomerID 
  and RelationShip ='0107'
;
  --1个值
  select CustomerID into s2 from customer_info 
  where customerid=sCustomerID;
 
if(sType=1) then
s3:=s1;
  else
  s3:=s1+s2;--我需要的是前面2个合起来的结果,着句也有问题
end if;     select sum(gethistorybalance(BP.LoanAccount,to_char(sysdate,'yyyy/mm/dd'),'AllBalance',BP.BusinessNo,BP.PutOutNo)) into Result
  from business_putout bp
  where applicantid in ( s3);--得到的在着,再次计算
  return(Result);
end ;

解决方案 »

  1.   

    我想知道如何写才不会报错,允许返回多行数值
    我需要把customerid先计算出来,因为实际的sql比较长
    希望大侠们回答下!谢谢!
      

  2.   

    使用select s1:=CustomerID from CUSTOMER_RELATIVE
      

  3.   

    谢谢楼上的!
    我马上试下
    实际上主要的怎么把2个结果连起来,实际SQL比较长,不好用union来连
      

  4.   

    Compilation errors for FUNCTION BANK.TEST04Error: PL/SQL: ORA-00923: 未找到预期 FROM 关键字
    Line: 10
    Text: select s1=CustomerID  from CUSTOMER_RELATIVEError: PL/SQL: SQL Statement ignored
    Line: 10
    Text: select s1=CustomerID  from CUSTOMER_RELATIVEError: PL/SQL: ORA-00923: 未找到预期 FROM 关键字
    Line: 14
    Text: select s2:=CustomerID  from customer_infoError: PL/SQL: SQL Statement ignored
    Line: 14
    Text: select s2:=CustomerID  from customer_info
    楼上的,不可以啊!我的是oracle 8i
    我需要的是前面2个sql结果的和