各位高手看看我写的存储过程有没有问题  如果有 问题在那里  以及 怎么调用这个存储过程或者说怎么测试这个存储过程create or replace package pkg_gfwf_fwlx is  TYPE Result_Cur is REF CURSOR;
  PROCEDURE SP_Rpt_Leave(yyyy number,fwlx varchar2,dw varchar2,qy VARCHAR2,hy varchar2,p_Result out Result_Cur);end;create or replace package body pkg_gfwf_fwlx IS
  PROCEDURE SP_Rpt_Leave(yyyy number,fwlx varchar2,dw varchar2,qy VARCHAR2,hy varchar2,p_Result out Result_Cur) IS
  v_SQL VARCHAR2(4000);
  BEGIN
  v_SQL :='select rownum,a.entname,b.name qyname, d.name hyname ,f.zlmc zlmc , nvl(g.this_year,0) this,nvl(e.spsj,0)sbl,nvl(h.last_year,0)last_year
from gfwf_gfcsdw a 
left outer join code_region b on substr(a.regioncode,1,6)=b.code 
left outer join gfwf_sbdj_qyjbxx c on c.wrybh=a.WRYBH and to_char(c.apply_date,''yyyy'') ='||yyyy||'
left outer join gfwf_sbhylb d on nvl(c.hylb,8)=d.code 
left outer join gfwf_sbdj_fwcsqxqk e on c.gfsbdjbh=e.gfsbdjbh and e.fwlb=2 and e.fwlx ='||fwlx||'
left join gfwf_fwzl f on f.zlbh='||fwlx||'
left outer join (  select  
  d.entname dwmc,to_char(apply_date,''yyyy'')sj ,fwlx ,sum(SL) this_year
  from gfwf_gfcsdw d 
  left outer join 
  ( select * from GFWF_ZYLD a  inner join GFWF_ZYLD_WXFW b on a.zyldh=b.zyldh and  fwlx='||fwlx||' ) a 
  on d.WRYBH=a.csdwbh and to_char(apply_date,''yyyy'')='||yyyy||'
  group by d.entname, to_char(apply_date,''yyyy'') ,fwlx 
)g on g.dwmc=a.entname and e.fwlx=g.fwlx and to_char(c.apply_date,''yyyy'')=g.sj
left outer join (  select  
  d.entname dwmc,to_char(apply_date,''yyyy'')sj ,fwlx,sum(SL) last_year
  from gfwf_gfcsdw d 
  left outer join 
  ( select * from GFWF_ZYLD a  inner join GFWF_ZYLD_WXFW b on a.zyldh=b.zyldh and fwlx='||fwlx||') a 
  on d.WRYBH=a.csdwbh  and to_char(apply_date,''yyyy'')='||yyyy||'-1
  group by d.entname, to_char(apply_date,''yyyy'') ,fwlx 
)h on h.dwmc=a.entname and e.fwlx=h.fwlx and to_char(c.apply_date,''yyyy'')=h.sjwhere  a.ENTNAME like  ''%'||dw||'%'' 
';
  IF qy IS NOT NULL THEN
  v_SQL := v_SQL || ' AND b.code = '||qy;
  END IF;
  IF hy IS NOT NULL THEN
  v_SQL := v_SQL || ' AND d.code = '||hy;
  END IF;  v_SQL := v_SQL||' order by rownum';  open p_Result for v_SQL ;
  END SP_Rpt_Leave;
end; --end package

解决方案 »

  1.   

    你直接把你的错误贴出来不就完了,这么长,谁有心思看
    这个要有错的话,应该就是 v_sql 拼的有问题
    你试一下,create table test(text varchar2(4000));
    拼接好以后,insert into test values(v_sql);然后把拼出来的 sql 拿出来看有什么问题
      

  2.   


    declare
        r_cursor     pkg_gfwf_fwlx.Result_Cur;
    begin
        pkg_gfwf_fwlx.SP_Rpt_Leave(2011,'a','b','c','d', r_cursor);
    end;
    /
      

  3.   

    编译能通过有什么用,v_sql 拼接错了,编译的时候是不知道的,只有执行的时候才知道有没有问题
      

  4.   

    我就是不知道sql拼没拼错 所以要执行一下试试 所以问怎么调用这个存储过程  在oracle中
      

  5.   


    declare
        r_cursor     pkg_gfwf_fwlx.Result_Cur;
    begin
        pkg_gfwf_fwlx.SP_Rpt_Leave(2011,'a','b','c','d', r_cursor);
    end;这样就可已调用了。
      

  6.   

    这个是包头,和包体,不是存储过程
    包头中定义正确了,但包体中有问题啊》
    create or replace package body pkg_gfwf_fwlx 
    IS
    BEGIN
     create PROCEDURE SP_Rpt_Leave(yyyy number,fwlx varchar2,dw varchar2,qy VARCHAR2,hy varchar2,p_Result out Result_Cur) IS
      v_SQL VARCHAR2(4000);end;这样创建包体才符合逻辑吧