declare
num number;
select count(*) into num from USER_TABLE
where CALLERID=@dncallerid;
if num>0 then --有记录
...
else --没记录
...
end if;
num number;
select count(*) into num from USER_TABLE
where CALLERID=@dncallerid;
if num>0 then --有记录
...
else --没记录
...
end if;
不好,慢试一下 max(rownum) 代替 count(*)行不行?我手边没有环境,不能替你试
select * from USER_TABLE where CALLERID='asdad';
if sql%rowcount>0 then
....
end if;
end;
sql%rowcount为所查数据数
这样试试
select nvl(1,0) into num from dual where exist (select 1 from USER_TABLE
where CALLERID=@dncallerid)
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;