zoukankan      html  css  js  c++  java
  • 【PL/SQL练习】游标cursor :oracle 在执行sql语句时,为sql语句所分配的一个私有的内存区域

    隐式游标:一次只能返回一行结果(不需要定义,默认自动建立)
      显式游标: 需要开发人员提前定义,可以通过循环的方式处理游标里的sql语句,返回多行结果
     
      隐式游标的属性:
       sql%rowcout    统计在游标中处理的记录数
       sql%found      如果在游标中能找到符合条件的一条记录,结果为true
       sql%notfound   如果在游标中能找不到符合条件的一条记录,结果为true
       sql%isopen     判断游标是否打开,在隐式游标中默认游标自动打开

    1.隐式游标:

    sql%notfound   如果在游标中能找不到符合条件的一条记录,结果为true  
    SQL> declare
      2  
      3    v_id t1.id%type;
      4  
      5  begin
      6  
      7    v_id :=10;
      8  
      9    update t1 set id=20 where id=v_id;
     10    if  sql%notfound then
     11    insert into t1(id) values (v_id);
     12    commit;
     13    end if;
     14  end;

    2. sql%found      如果在游标中能找到符合条件的一条记录,结果为true

    SQL> declare
      2  
      3    v_id t1.id%type;
      4  
      5  begin
      6  
      7    v_id :=10;
      8  
      9    delete from t1 where id = v_id;
     10  
     11    if  sql%found then
     12    dbms_output.put_line('T1 recorder is delete !');
     13    commit;
     14    end if;
     15  end;

    3.sql%rowcout    统计在游标中处理的记录数

    SQL> declare
      2  
      3    v_id t1.id%type;
      4  
      5  begin
      6  
      7    v_id :=10;
      8  
      9    insert into t1 (id) values (v_id);
     10    delete from t1 where id = v_id;
     11  
     12    if  sql%found then
     13    dbms_output.put_line('T1 recorder is delete !');
     14    dbms_output.put_line('T1 recorders '||sql%rowcount||' rows was deleted !');                //统计删除的行数
     15    commit;
     16    end if;
     17  end;


     

  • 相关阅读:
    cocos2dx-lua UI编辑器的设计思路
    软件中Undo(撤回)和Redo(重做)的实现
    Cocos2d-x上适合做工具的UI库:ImGui
    静态成员
    命名空间
    类对象的初始化
    函数的重载、重写与隐藏
    类的继承关系与访问限定符
    多继承
    友元函数与友元类
  • 原文地址:https://www.cnblogs.com/tomatoes-/p/6104302.html
Copyright © 2011-2022 走看看