1. 首页
  2. IT资讯

隐式游标(implicit cursor)_sql%found_rowcount小操作

#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博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-665812/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:℅傍ㄖ免沦陷dε鬼,转转请注明出处:http://www.cxybcw.com/192822.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code