写了一个存储过程:
create or replace procedure ceshi(strdate in out date,enddate in out date) is
  --声明局部变量
   ...
begin
  
  select id,name into t_id,t_name from table where createdate>=strdate and createdate<=enddate;...
end;执行部分都没有任何问题。
现在要调用这个存储过程,用了以下几种方法:
1、
begin
    ceshi(strdate => :to_date('2007-03-01','yyyy-mm-dd'),
          enddate => :to_date('2007-04-01','yyyy-mm-dd');
end;
2、
  declare
   strshijian date;
   endshijian date;
  begin
   strshijian:=to_date('2007-03-01','yyyy-mm-dd');
   endshijian:=to_date('2007-04-01','yyyy-mm-dd');
    ceshi(strdate => :strshijian,
          enddate => :endshijian);
  end;
3、
    declare
   strshijian date;
   endshijian date;
  begin
   strshijian:='2007-03-01';
   endshijian:='2007-04-01';
    ceshi(strdate => :strshijian,
          enddate => :endshijian);
  end;
4、
  begin
    ceshi(strdate => :'2007-03-01',
          enddate => :'2007-04-01';
 end;执行后全都提示:
 ora-01036:非法的变量名/编号如果在ceshi存储过程中不带参数,直接在过程内定义赋值strdate、enddate执行却没有一点问题。小弟初学oracle,问题都很幼稚,让大家见笑了!

解决方案 »

  1.   

    调用处不要冒号。存储过程中,如果strdate和enddate变量的值不会改变,那么就只申明为in。
      

  2.   

    改成:
    1、
    begin
        ceshi(strdate => to_date('2007-03-01','yyyy-mm-dd'),
              enddate => to_date('2007-04-01','yyyy-mm-dd');
    end;
    2、
      declare
       strshijian date;
       endshijian date;
      begin
       strshijian:=to_date('2007-03-01','yyyy-mm-dd');
       endshijian:=to_date('2007-04-01','yyyy-mm-dd');
        ceshi(strdate => strshijian,
              enddate => endshijian);
      end;
    3、
        declare
       strshijian date;
       endshijian date;
      begin
       strshijian:='2007-03-01';
       endshijian:='2007-04-01';
        ceshi(strdate => strshijian,
              enddate => endshijian);
      end;
    4、
      begin
        ceshi(strdate => '2007-03-01',
              enddate => '2007-04-01';
     end;