我创建了一个存储过程内容如下
create or replace procedure summary(sdate in varchar2,org in varchar2,manager in varchar2)asbegin
if(manager == '')
{
        DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0 and t.khjl=manager and t.FLJZRQ like sdate and t.fb in org;
}
else
  {
        DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org;
  }
 BEGIN 
FOR rdata IN cdata 
 LOOP 
   
  if(rdata.Cf_yj == '01')
  {
       insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Normalcount,Normalnumber,Normalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
  }
  else if(rdata.Cf_yj == '02')
  {
         insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Focuscount,Focusnumber,Focusmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
  }
   else if(rdata.Cf_yj == '03')
  {
         insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Secondarycount,Secondarynumber,Secondarymoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
  }
   else if(rdata.Cf_yj == '04')
  {
         insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Doubtcount,Doubtnumber,Doubtmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
  }
   else if(rdata.Cf_yj == '05')
  {
         insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Lostcount,Lostnumber,Lostmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
  }
  
 END LOOP; 
END;return select * from xe.tmp_DKFLHZB;end;
/然后执行 提示成功 
然后我执行execute   summary('2013-03%','03110331','')
提示ora 00900 无效 sql语句然后我去存储过程列表那里点 测试 提示 summary无效,,,
到底哪里出了问题?sql存储

解决方案 »

  1.   

    提示 summary无效,,,
    ====================
    编译有问题,存储过程处于 invalid 状态
      

  2.   

    反正我就知道plsql里面的判断不是用==
      

  3.   

    我又改了改还是不行。
    我又改了改
    create or replace procedure c(sdate in varchar2,org in varchar2,manager in varchar2)asbegin
    if(manager = '') then
    begin        DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0 and t.khjl=manager and t.FLJZRQ like sdate and t.fb in org;
    end;
    else
    begin
            DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org;
    end;
    end if;BEGIN 
    FOR rdata IN cdata 
     LOOP 
       
      if(rdata.Cf_yj = '01')
      {
           insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Normalcount,Normalnumber,Normalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
      }
      else if(rdata.Cf_yj = '02')
      {
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Focuscount,Focusnumber,Focusmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
      }
       else if(rdata.Cf_yj = '03')
      {
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Secondarycount,Secondarynumber,Secondarymoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      }
       else if(rdata.Cf_yj = '04')
      {
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Doubtcount,Doubtnumber,Doubtmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      }
       else if(rdata.Cf_yj = '05')
      {
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Lostcount,Lostnumber,Lostmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      }
      
     END LOOP; 
    END;return select * from xe.tmp_DKFLHZB;end xe.summary ;
    /
      

  4.   

    存储过程里没有{} 也不能用 ==表示判断 也不能写else if (elsif)你先把语法弄明白了再说,你连油门和离合器都不知道在哪,还问别人“这车到底怎么开”,神仙也解决不了。
      

  5.   

    又改了下,现在报错
    PROCEDURE XE.C 编译错误错误:PLS-00103: 出现符号 "CURSOR"在需要下列之一时:
            := . ( @ % ;
    行:9
    文本:DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0 and t.khjl=manager and t.FLJZRQ like sdate and t.fb in org;改后的存储过程  create or replace procedure c(sdate  varchar2,org  varchar2,manager  varchar2)asbegin
    if(manager = '') then
    begin        DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0 and t.khjl=manager and t.FLJZRQ like sdate and t.fb in org;end;
    else
    begin
            DECALRE CURSOR tmpdata IS select distinct(t.khjl) ,t.fb,t.fljzrq,t.id,t.dkye from xe.xe_qkflrdb t where t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org;
    end;
    end if;BEGIN
    FOR rdata IN cdata
     LOOP  if(rdata.Cf_yj = '01')
      BEGIN
           insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Normalcount,Normalnumber,Normalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
      end;
      else if(rdata.Cf_yj = '02')
      BEGIN
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Focuscount,Focusnumber,Focusmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye)
      end;
       else if(rdata.Cf_yj = '03')
      BEGIN
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Secondarycount,Secondarynumber,Secondarymoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      end;
       else if(rdata.Cf_yj = '04')
      BEGIN
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Doubtcount,Doubtnumber,Doubtmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      end;
       else if(rdata.Cf_yj = '05')
      BEGIN
             insert into xe.tmp_DKFLHZB(Key,name,org,name,Summaymonth,Totalcount,Totalnumber,Totalmoney,Lostcount,Lostnumber,Lostmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) values('Company'+rdata.ID,rdata.khjl,rdata.fb,sdate,1,1,sdata.dkye,1,1,sdata.dkye,1,1,sdata.dkye)
      end;
      end if; END LOOP;
    END;return select * from xe.tmp_DKFLHZB;end xe.summary ;
      

  6.   

    给你个例子吧,你写的有些乱
    create or replace procedure 
         tj_invpay2(vseqno in number)
    as
      i    number;
      ii    number;
      lmzkje number;
      iiii    number;
      lydkje    number;
      row_main     inv_main%rowtype; cursor cur_pay2 is
    select * from inv_pay2
    where seqno=vseqno and mxcode='09'; 
     begin
     select * into row_main from inv_main
    where seqno=vseqno and flag='N' for update;
      if(row_main.mzk<>0) then
         for r_pay2 in cur_pay2 loop
             select count(*) into i from custom where code=r_pay2.zpno and hyklb='9' and hy='0';
             if i > 0 then
               update inv_pay2 set mxcode='15' where seqno=vseqno and zpno=r_pay2.zpno;
             end if;
         end loop;
         select count(*) into ii from INV_PAY2 where  mxcode='09' and seqno=vseqno;
         if(ii<>0) then 
         SELECT  SUM(nvl(JE,0)) into lmzkje FROM INV_PAY2   WHERE   mxcode='09' and seqno=vseqno;
         end if;
         if lmzkje is not null then 
         UPDATE INV_MAIN SET MZK= lmzkje  WHERE  seqno=vseqno;
         else
         UPDATE INV_MAIN SET MZK= 0  WHERE  seqno=vseqno;
         end if;
         select count(*) into iiii from INV_PAY2 where  mxcode='15' and seqno=vseqno;
         if(iiii<>0) then
         SELECT  SUM(JE) into lydkje FROM INV_PAY2   WHERE   mxcode='15' and seqno=vseqno;
         end if;
         UPDATE INV_MAIN SET PAY12=lydkje  WHERE  seqno=vseqno;
      end if ;
      --commit;  exception when others then
    rollback;
    raise;
    end;
      

  7.   

    算了不用游标了,oracle的游标太垃圾了,哦换了一种方式,大家看看
    但是最后一句那里报错。  select * from xe.tmp_DKFLHZB;存储过程主体
    create or replace procedure c(sdate in varchar2,org in varchar2)
    as
    BEGIN
      
      insert into xe.tmp_DKFLHZB(Key,name,org,Summaymonth,Totalcount,Totalnumber,Totalmoney,Normalcount,Normalnumber,Normalmoney) 
      select 'Company'||ID,khjl,fb,sdate,1,1,dkye,1,1,dkye
      from xe_qkflrdb t
      where  t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org and  Cf_yj='01';  insert into xe.tmp_DKFLHZB(Key,name,org,Summaymonth,Totalcount,Totalnumber,Totalmoney,Focuscount,Focusnumber,Focusmoney) 
      select 'Company'||ID,khjl,fb,sdate,1,1,dkye,1,1,dkye
      from xe_qkflrdb t
      where  t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org and  Cf_yj='02';  insert into xe.tmp_DKFLHZB(Key,name,org,Summaymonth,Totalcount,Totalnumber,Totalmoney,Secondarycount,Secondarynumber,Secondarymoney,Badtotalcount,Badtotalnumber,Badtotalmoney) 
      select 'Company'||ID,khjl,fb,sdate,1,1,dkye,1,1,dkye,1,1,dkye
      from xe_qkflrdb t
      where  t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org and  Cf_yj='03';  insert into xe.tmp_DKFLHZB(Key,name,org,Summaymonth,Totalcount,Totalnumber,Totalmoney,Doubtcount,Doubtnumber,Doubtmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) 
      select 'Company'||ID,khjl,fb,sdate,1,1,dkye,1,1,dkye,1,1,dkye
      from xe_qkflrdb t
      where  t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org and  Cf_yj='04';  insert into xe.tmp_DKFLHZB(Key,name,org,Summaymonth,Totalcount,Totalnumber,Totalmoney,Lostcount,Lostnumber,Lostmoney,Badtotalcount,Badtotalnumber,Badtotalmoney) 
      select 'Company'||ID,khjl,fb,sdate,1,1,dkye,1,1,dkye,1,1,dkye
      from xe_qkflrdb t
      where  t.khjl is not null  and t.cf_yj is not null and t.dkye>0  and t.FLJZRQ like sdate and fb in org and  Cf_yj='05';  select * from xe.tmp_DKFLHZB;EXCEPTION
         WHEN NO_DATA_FOUND THEN
           return; end c ;
      

  8.   

    你不用改,你把语法弄明白之前改不对。Oracle没有MSSQLServer那么烂,不看完代码都不知道存储过程里有几个返回。Oracle想传回select结果集,必须声明动态游标作为out参数。
      

  9.   

    在oracle的存储过程里面要使用select要有承接变量(如:select t.tb into tb_varchar from table t)
      

  10.   

    先学会oracle基本的用法再来问吧,闭着眼睛瞎改有什么意义
      

  11.   

    哦买糕的,楼主这是PLJQL吗?
      

  12.   

    用plsqldeveloper工具看下这个存储过程的定义,如果这个存储过程编译有问题,会提示是在哪一行出错了
      

  13.   

    先写个最简单的存储过程了解一下
    存储过程中不能直接用select * from tab_name
    想返回结果集的话,可以使用游标或集合
      

  14.   

    应该要select xx into xx吧