zoukankan      html  css  js  c++  java
  • 游标 cursor


    a 定义游标——Cursor [ Cursor Name[param_name, param_type]] IS select xxx from xxxwhere xxx;

    b 打开游标——Open [ Cursor Name[varialbe_value] ] ;

    c 操作游标——Fetch [ Cursor Name ];

    d 关闭游标——Close [ Cursor Name ] ;

    常见显式Cursor用法:
    1使用for循环来使用cursor:

    create or replace procedure test_cursor is
    cursor cur is select * from test_tb where id1 = 1;
    userinfo test_tb%rowtype;
    begin
    for userinfo in cur loop
    exit when cur%notfound;--退出循环当返回最后一条语句为假
    dbms_output.put_line('user id : ' || userinfo.id1 || '-' ||
    'user name : ' || userinfo.name1);
    end loop;

    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end test_cursor;
    2使用fetch来使用cursor:

    create or replace procedure test_fc
    is
    cursor cur is select * from test_tb where id1=1;
    b test_tb%rowtype;
    begin
    open cur;
    loop
    exit when cur%notfound;
    fetch cur into b;
    dbms_output.put_line('user id : ' ||b.id1 || '-' ||
    'user name : ' ||b.name1);

    end loop;
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    end test_cursor;

    end test_fc;

  • 相关阅读:
    HDU1316 fib+高精度
    HDU1868
    HDU2586 LCA
    HDU1113 字符串处理
    HDU1115 几何+多边形重心
    HDU1124
    HDU1110 几何
    HDU1103
    HDU2670 DP
    linux 下查看机器是cpu是几核的
  • 原文地址:https://www.cnblogs.com/steel-chen/p/6889201.html
Copyright © 2011-2022 走看看