oracle-游标

1. 游标

  用途:利用游标来访问记录集合同的每条记录
  分类:分为静态游标、动态游标;

2. 静态游标

2.1定义游标

  语法:cursor 游标名称 is 查询语句 

cursor bd_psndoc is select name,code,id from psndoc;

2.2定义变量

  指定数据类型:psn_id varchar2(20);
  参照定义: psn_id psndoc.id%type;
  行变量: psn psndoc%rowtype;

2.3游标读取

  open 游标名称

  fetch 游标名称 into 变量

2.4属性

  found:获得记录为TRUE,否则FALSE
  not found:
  rowcount:返回记录条数
  isopen:判断游标是否打开,作用于open、close

3. 动态游标

3.1 定义游标

  语法1:type 游标类型 is ref cursor
       return 记录类型
  语法2 :type 游标类型 is ref cursor
       游标名称 游标类型

create or replace procedure p_hr_quanxian ( v_userid in varchar2,cur_1 out sys_refcursor) IS
mydeal sm_dpprofile_reg%rowtype;
cursor mycursor is select * from sm_dpprofile_reg where resourceid=1002Z71000000000C4R7and cuserid= v_userid ;
-- TYPE My_CurType IS REF CURSOR;
-- CUR_1 My_CurType;
select_str varchar2(100);
begin
open mycursor;
loop
fetch mycursor into mydeal;
exit when mycursor%notfound;
select_str :=select pk_doc from ||mydeal.dptablename;
open CUR_1 for select_str;
-- loop 
-- fetch CUR_1 into v_hrqx;
-- exit when CUR_1%notfound;
-- insert into hr_quanxian values (mydeal.cuserid,v_hrqx);
-- dbms_output.put_line(mydeal.cuserid||v_hrqx) ; 
-- end loop;
-- close CUR_1;
end loop;
close mycursor; 
commit;
end;

oracle-游标

上一篇:Lost connection to MySQL server during query的几种可能


下一篇:使用goaccess分析nginx日志