游标

作者: Java_Evan | 来源:发表于2019-05-22 11:36 被阅读0次

    游标-处理多行数据类型

    --方法一

    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;

    相关文章

      网友评论

          本文标题:游标

          本文链接:https://www.haomeiwen.com/subject/mddyzqtx.html