zoukankan      html  css  js  c++  java
  • oracel的游标用法

    --游标中的while循环---
    declare
      cursor mycursor is
        select * from sys_bank;
      myrecord sys_bank%rowtype;
    begin
      --打开游标--
      open mycursor;
      --捕捉游标--
      fetch mycursor
        into myrecord;
        --循环之前一定要fetch一把
      while mycursor%found loop
        dbms_output.put_line(myrecord.bank_id || ' ' || myrecord.bank_name || ' ' ||
                             myrecord.flag);
        fetch mycursor
          into myrecord;
      end loop;
      --关闭游标
      close mycursor;
    end;

    --带参数的游标,exit..when循环--
    declare
      cursor mycursor(v_bank_id varchar2) is
        select * from sys_bank where bank_id = v_bank_id;
      myrecord sys_bank%rowtype;
    begin
      open mycursor('3');
      loop
        fetch mycursor
          into myrecord;
        exit when mycursor%notfound;
        dbms_output.put_line(myrecord.bank_id || ' ' || myrecord.bank_name || ' ' ||
                             myrecord.flag);
      end loop;
      close mycursor;
    end;

    --用for循环游标 不需要手动打开游标也不需要手动关闭--
    declare
      cursor mycursor(v_bank_id varchar2) is
        select * from sys_bank where bank_id = v_bank_id;
    begin
      for cur in mycursor('3')
      loop
          dbms_output.put_line(cur.bank_id || ' ' || cur.bank_name || ' ' ||
                             cur.flag);
      end loop;
    end;

  • 相关阅读:
    最大子序列和问题之算法优化
    数据揭秘:低学历成功逆袭概率有多少?感谢父母送我读书!
    据说这份高考卷,只有程序员能得满分!
    牛客OI赛制测试赛2
    斯特林公式
    N!的近似值_斯特林公式
    矩阵快速幂
    回文树
    回文树入门
    环和链的判断
  • 原文地址:https://www.cnblogs.com/working/p/2918954.html
Copyright © 2011-2022 走看看