Oracle 使用标量变量接收游标数据

来源:互联网 发布:病毒 知乎 编辑:程序博客网 时间:2024/06/10 17:20
-- 使用标量变量接收游标数据
declare
 v_id tg_test_user.tg_test_userid%type;             -- 创建一个类型与tg_test_user表中的tg_test_userid列相同的标量变量 v_id
 v_name  tg_test_user.tg_test_username%type;
 v_pwd  tg_test_user.tg_test_password%type;
 
 cursor e_cursor is                                                            -- 定义游标
    select * from tg_test_user;
begin
  open e_cursor;                                                            --打开游标
  loop
    fetch e_cursor into v_id,v_name,v_pwd;                                                                        -- 提取数据
    exit when e_cursor%notfound;
    dbms_output.put_line('用户名:'||v_name||',密码:'||v_pwd||',ID:'||v_id);                       -- 输出
  end loop;
  close e_cursor;                                                                  -- 关闭游标
end;
0 0
原创粉丝点击