ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 隐式游标(implicit cursor)_sql%found_rowcount小操作

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

原创 Linux操作系统 作者:wisdomone1 时间:2010-06-21 19:07:16 0 删除 编辑
#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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12690169