各位大虾,小弟初次写oracle的存储过程,请帮忙看下:Create or replace package S_pkg 
is
  type ResultRows is ref cursor;
  procedure pCt(staffId varchar2, startDate varchar2,
                       endDate varchar2, resultRows ResultRows);
end S_pkg;
/
create or replace package body S_pkg isprocedure pCt(  staffId       VARCHAR2,
  startDate     VARCHAR2,
  endDate       VARCHAR2, 
  resultRows out  ResultRows

is
  sDate VARCHAR2(7) := to_char(add_months(sysdate,-12),'yyyy-MM');
  eDate VARCHAR2(7) := to_char(sysdate, 'yyyy-MM');
begin
  if startDate is not null then
    sDate := startDate;
  end if;
  if endDate is not null then
    eDate := endDate;
  end if;  open resultRows for
  select count(*) as counts,
         p.provname as provname, 
         to_char(d.reg_date, 'yyyy-MM') as reg_date
  from   domain d, contact c, province p
  where  d.staff_id = staffId
         and to_char(d.reg_date, 'yyyy-MM') > sDate
         and to_char(d.reg_date, 'yyyy-MM') <= eDate
         and d.registrant = c.contact_id
         and c.sp = p.provinceid 
  group by p.provname, to_char(d.reg_date, 'yyyy-MM')
  order by p.provname, to_char(d.reg_date, 'yyyy-MM');
end;
end S_pkg;
/
每次执行都会出现“子程序或游标'pCt'已在程序包说明中说明,必须在程序包体中对其进行定义。”

解决方案 »

  1.   

    这里不分大小写,
    Create or replace package S_pkg 
    is 
      type ResultRows is ref cursor; 
      procedure pCt(staffId varchar2, startDate varchar2, 
                          endDate varchar2, resultRow ResultRows); 
    end S_pkg; 

    create or replace package body S_pkg is procedure pCt(   staffId      VARCHAR2, 
      startDate    VARCHAR2, 
      endDate      VARCHAR2, 
      resultRow out  ResultRows 

    is 
      sDate VARCHAR2(7) := to_char(add_months(sysdate,-12),'yyyy-MM'); 
      eDate VARCHAR2(7) := to_char(sysdate, 'yyyy-MM'); 
    begin 
      if startDate is not null then 
        sDate := startDate; 
      end if; 
      if endDate is not null then 
        eDate := endDate; 
      end if;   open resultRow for 
      select count(*) as counts, 
            p.provname as provname, 
            to_char(d.reg_date, 'yyyy-MM') as reg_date 
      from  domain d, contact c, province p 
      where  d.staff_id = staffId 
            and to_char(d.reg_date, 'yyyy-MM') > sDate 
            and to_char(d.reg_date, 'yyyy-MM') <= eDate 
            and d.registrant = c.contact_id 
            and c.sp = p.provinceid 
      group by p.provname, to_char(d.reg_date, 'yyyy-MM') 
      order by p.provname, to_char(d.reg_date, 'yyyy-MM'); 
    end; 
    end S_pkg; 

      

  2.   

    楼上的兄弟 我按照你这种写法 也不行啊!!还是Compilation errors for PACKAGE BODY E.S_PKGError: PLS-00323: 子程序或游标 'PROVINCECOUNT' 已在程序包说明中说明,必须在程序包体中对其进行定义。
    Line: 4
      

  3.   

    楼上的兄弟 我按照你这种写法 也不行啊!! Compilation errors for PACKAGE BODY E.S_PKGError: PLS-00323: 子程序或游标 'PCT' 已在程序包说明中说明,必须在程序包体中对其进行定义。
    Line: 4
      

  4.   

    这么写
    Create or replace package S_pkg 
    is 
      type ResultRows is ref cursor; 
      procedure pCt(staffId varchar2, startDate varchar2, 
                          endDate varchar2, resultRow out ResultRows); 
    end S_pkg; 

    create or replace package body S_pkg is procedure pCt(   staffId      VARCHAR2, 
      startDate    VARCHAR2, 
      endDate      VARCHAR2, 
      resultRow out  ResultRows 

    is 
      sDate VARCHAR2(7) := to_char(add_months(sysdate,-12),'yyyy-MM'); 
      eDate VARCHAR2(7) := to_char(sysdate, 'yyyy-MM'); 
    begin 
      if startDate is not null then 
        sDate := startDate; 
      end if; 
      if endDate is not null then 
        eDate := endDate; 
      end if;   open resultRow for 
      select count(*) as counts, 
            p.provname as provname, 
            to_char(d.reg_date, 'yyyy-MM') as reg_date 
      from  domain d, contact c, province p 
      where  d.staff_id = staffId 
            and to_char(d.reg_date, 'yyyy-MM') > sDate 
            and to_char(d.reg_date, 'yyyy-MM') <= eDate 
            and d.registrant = c.contact_id 
            and c.sp = p.provinceid 
      group by p.provname, to_char(d.reg_date, 'yyyy-MM') 
      order by p.provname, to_char(d.reg_date, 'yyyy-MM'); 
    end; 
    end S_pkg; 

      

  5.   

    哎,还有不对的地方,错误太多了
    倒数第二行..............
      group by p.provname, to_char(d.reg_date, 'yyyy-MM') 
      order by p.provname, to_char(d.reg_date, 'yyyy-MM'); 
    end pCt
    end S_pkg;
      

  6.   


    这个pCt我记得可以不用写的,直接end就可以了,再试试。。