虽然搞了好久的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;
-