declare
num number;
select count(*) into num from USER_TABLE 
          where CALLERID=@dncallerid;
if num>0 then --有记录
...
else  --没记录
...
end if;

解决方案 »

  1.   

    count(*) 消耗资源太多
    不好,慢试一下 max(rownum) 代替 count(*)行不行?我手边没有环境,不能替你试
      

  2.   

    begin
    select * from USER_TABLE where CALLERID='asdad';
    if sql%rowcount>0 then
    ....
    end if;
    end;
    sql%rowcount为所查数据数
      

  3.   

    可能不行
    这样试试
    select nvl(1,0) into num from dual where exist (select 1 from USER_TABLE 
              where CALLERID=@dncallerid)
      

  4.   

    wenming168(清风) :学习,谢谢
      

  5.   

    如果是insert,update那么可以用 sql%rowcount
      

  6.   

    应该是 if sql%rowcount>0 then ...
      

  7.   

    select * from USER_TABLE where CALLERID='asdad';
             if sql%rowcount>0 then
    如果没有找到记录,会触发NO_DATA_FOUND异常,不会执行到if sql%rowcount>0 then。可以直接删除就行。
    例:
    delete from USER_TABLE where CALLERID=dncallerid;
    if sql%rowcount <> 0 
    then
      dnCode := 1;
    end if;
    insert into USER_TABLE(CALLERID,RETIME,FLAG) values (dncallerid,sysdate,0)
    commit;