游标

游标-处理多行数据类型

--方法一

declare

    --定义游标

    cursor user_sum_cursor is select sum,name,time from user where id = 1;

begin

    for i in user_sum_cursor  loop

        dbms_output.put_line(i.sum || ',' || i.name || ',' || i.time);

    end loop;

end;


--方法二

declare

    --定义记录类型

    type user_record is record(

            v_sum user.sum%type,

            v_id user.id%type,

            v_email user.email%type

    );

    --声明记录类型的成员变量

    v_user_record user_record;

    --定义游标

    cursor user_sum_cursor is select sum,id,email from user where id=1;

begin

    --打开游标

    open user_sum_cursor;

    --提取游标

    fetch user_sum_cursor into v_user_record;

    --循环判断游标是否有值,%found为空值

    while user_sum_cursor%found loop

        dbms_output.put_line(v_user_record.v_sum || ',' || v_user_record.id || ',' || v_user_record.email);

        fetch user_sum_cursor into v_user_record;

    end loop;

    --关闭游标

   close user_sum_cursor;

end;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,273评论 0 0
  • cursor 游标:游标表示一个虚拟的结果集,相当于java中的引用(地址) 具体表示的是由selec...
    圣贤与无赖阅读 559评论 0 1
  • 1、Check规则 Check (Agebetween15and30 )把年龄限制在15~30岁之间 2、新SQL...
    姜海涛阅读 1,070评论 0 4
  • 在数据库中,游标是一个十分重要的概念。游标提供了一种对从表中检索出的数据进行操作的灵活手段,就本质而言,游标实际上...
    码谜妈咪阅读 4,941评论 0 4
  • 我是谁,这真是一个复杂的哲学问题。毕竟这不是用“名字”可以回答得了的。 我们可能会以为,我之所以是我,都是我们自己...
    兰草香舍2018阅读 254评论 0 0

友情链接更多精彩内容