+ -
当前位置:首页 → 问答吧 → 存储过程老是出错?

存储过程老是出错?

时间:2011-11-17

来源:互联网

C# code

declare   
  cid   number(20); 
begin
   select a.id into cid   from b_table a where a.mac='911:34:34:34:GG:GG';
   if cid >0
     then
        update 语句;
   else
      insert 语句;
     end if;
 commit; 
exception
when others then
rollback;
end;



有一个问题,当where条件为真的时候,正确;但是当where条件为假,else就不会走,这是什么情况啊?

作者: yysyangyangyangshan   发布时间: 2011-11-17

当where条件找不到值的时候,就发生了NO_DATA_FOUND异常.直接rollback了.
解法:select 语句需要改成count计数方式
SQL code
declare   
  cid   number(20); 
begin
   select count(a.id) into cid   from b_table a where a.mac='911:34:34:34:GG:GG';
   if cid >0
     then
        select a.id into cid   from b_table a where a.mac='911:34:34:34:GG:GG';
        update 语句;
   else
      insert 语句;
     end if;
 commit; 
exception
when others then
rollback;
end;

作者: tx2730   发布时间: 2011-11-17

把declare去掉。

作者: redlotus_lyn   发布时间: 2011-11-17

热门下载

更多