create or replace procedure xt_test(xtNo number) is
begin
 update emp set sal=sal+100 where empno=xtNo;
end;
/上面定义一简单的存储过程,过程成功创建。
若执行 exec ex_test(9);提示“过程被成功完成”,
问题是 emp表中没有empno=9的人,怎么还提示过程成功完成?不解

解决方案 »

  1.   

    就算你把 update emp set sal=sal+100 where empno=9;在 sqlplus 中执行,它也只是会给一个 ‘0行更新’的提示,所以这个存储过程能正常运行。create or replace procedure xt_test(xtNo number) is
    begin
    update emp set sal=sal+100 where expno=xtNO;
    if sql%rowcount=0 then
    dbms_output.put_line('There is not this row');
    end if;
    end;
    /写成这个样子
    如果没有符合条件的记录的话就会给出提示。
      

  2.   


    --你写的过程与这句话没什么区别
    SQL> update emp
      2  set sal=sal+1000
      3  where empno='9'
      4  /
     
    0 rows updated
    --虽然没有更新,但是作为一个过程块,是成功执行的,
    --成功执行的过程块,即使没有更新任何行,难道还会报错?
      

  3.   

    过程执行成功不代表那个update成功
      

  4.   

    psufnxk2008的方法比较直观了,执行了可以的。看了你们说的,基本理解了。