#sql%found用于dml(delete,update,insert)及select into是否真正的操作了表
SQL> desc dept;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(20)
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 if sql%found then
6 dbms_output.put_line('the record deleted');
7 insert into dept values(10,'other');
8
9 end if;
10 end;
11 /
the record deleted
PL/SQL procedure successfully completed.
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
#sql%rowcount用于dml及select into影响表的多少行记录
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 dbms_output.put_line(to_char(sql%rowcount)||' number of dept deleted');
6 end;
7 /
0 number of dept deleted
PL/SQL procedure successfully completed.
SQL>
#sql%notfound
SQL> declare
2 v_name varchar2(20):='zxy';
3 begin
4 delete from dept where name=v_name;
5 if sql%notfound then
6 dbms_output.put_line('not found the record');
7 insert into dept values(88,v_name);
8 else
9 dbms_output.put_line('table dept total records '||to_char(sql%rowcount));
10 end if;
11 end;
12 /
not found the record
PL/SQL procedure successfully completed.
SQL> select * from dept;
ID NAME
---------- --------------------
10 other
88 zxy
SQL>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-665812/
,如需转载,请注明出处,否则将追究法律责任。