create table table1(did number,d_name varchar2(100));
insert into table1(did,d_name) values(1,'张');
insert into table1(did,d_name) values(2,'王');
insert into table1(did,d_name) values(3,'李');create or replace procedure test1(indid in number, outdn out varchar2) 
as
begin
  select d_name into outdn from table1 where did = indid;
exception
  WHEN OTHERS THEN
    DBMS_OUTPUT.LINE('wrong');
end test1;
create or replace procedure test2(indid in number, outdn out varchar2) 
as
declare 
  tmp_indid number;
begin
  tmp_indid := indid;
  select d_name into outdn from table1 where did = tmp_indid;
exception
  WHEN OTHERS THEN
    DBMS_OUTPUT.LINE('wrong');
end test2;declare
  s varchar2(100);
begin
  test1(2,s);
--  test2(2,s);
  DBMS_OUTPUT.LINE(s);
end;
请教:为什么执行test1查询不到结果出现'wrong',而test2就能得到结果,
初学望高手解答下,万分感谢!(环境oracle10g,pl/sql dev v6.0.5
上面是临时写的,无法测试,不计语法错误),只是问问:test1中直接把
传入的参数indid放在where条件后面就得不到结果,而test2中在存储过程 里面用个
临时变量,并将传入值付给临时变量,再在where条件后面用临时表量就能得到正
确结果了,为什么会这样?

解决方案 »

  1.   

    我把你的过程test1测试了一下,没有你说的那种情况,是不是你自己弄错了。还有就是虽然你用了异常处理,但是基本程序保护还是要有的。
      

  2.   

    感谢先,我test1就是通不过,后面输出始终 是wrong,改成test2就通过了,所以有点郁闷了!会不会有什么设置呢?
      

  3.   

    先把dbms_line换成dbms_output.put_line
    你最好测试一下
    两个过程应该结果应该是一样的
      

  4.   

    查到原因了,第一个存储过程写错了应是下面这个可能通不过,
    create   or   replace   procedure   test1(did   in   number,   outdn   out   varchar2)   
    as 
    begin 
        select   d_name   into   outdn   from   table1   where   did   =   did; 
    exception 
        WHEN   OTHERS   THEN 
            DBMS_OUTPUT.LINE('wrong'); 
    end   test1; 原因,did = did oracle不知道哪个是哪个了,谢谢二位