ORACLE 游标

虽然搞了好久的ORACLE了,但游标使用的很少,今天用了总结一下

 

需求:查出用户的手机和姓名,插入到另外一个表里。有个已经存在的存储过程,以游标的方式返回手机和姓名,现在需要编写一个存储过程调用已有的实现功能

 

遇到的问题:怎么定义一个游标,将返回的记读取并写入相应的表。以前定义游标都是

cursor cc is select empno,ename,job,sal
from emp where job = 'MANAGER';  类似这样的,现在不知道怎么弄了,经查询终于找到了方法

 

方法:

   1,定义返回游标的结构体

   2,定返回该结构体的游标即可,如下

-- Created on 2013-01-09 by THINK
declare
  -- Local variables here
  TYPE g_cursor IS REF CURSOR;
  TYPE employee IS RECORD(
    mobile_no  t_user.mobile_no%TYPE,
    name t_org.name%TYPE);
  type app_ref_cur_type is ref cursor return employee;
  v_final_status   number(10);
  v_message        varchar2(512);
  v_user_cursor  g_cursor;
  v_user_cursor1 app_ref_cur_type;
  employee1        employee;
begin
  -- Test statements here
  PKG_USER.getUserInfo(v_final_status,
                                       v_message,
                                       15,
                                       v_user_cursor);

  fetch v_user_cursor
    into employee1;
  while v_user_cursor%found loop
 
    insert into wlb_mobile_dd values (employee1.mobile_no);
    commit;
    fetch v_user_cursor
      into employee1;
  end loop;
end;

 

-

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值