你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 中游标的使用

[日期:2011-09-08] 来源:Linux社区  作者:myxx520 [字体:大 中 小]

 
  1.  declare cursor my_cur is select empno,deptno from emp;  
  2. employee_id emp.empno%type;  
  3. dept_id emp.deptno%type;  
  4. begin  
  5.   open my_cur;  
  6.   fetch my_cur into employee_id,dept_id;  
  7.   while my_cur%found loop  
  8.         dbms_output.put_line(employee_id||' shit '||dept_id);  
  9.         fetch my_cur into employee_id,dept_id;  
  10.   end loop;  
  11. end;  

使用行变量来获取游标信息

 
  1. declare cursor mycur is select * from emp;  
  2. var_emp emp%rowtype;  
  3. begin  
  4.       open mycur;  
  5.       fetch mycur into var_emp;  
  6.       while mycur%found loop  
  7.         dbms_output.put_line(var_emp.ename||':'||+to_char(var_emp.hiredate,'yyyy-MM-dd'));  
  8.         fetch mycur into var_emp;  
  9.       end loop;  
  10. end;  

隐式游标

 
  1. declare var_count integer;  
  2. begin  
  3.    update A set ename='B';  
  4.    var_count:=sql%rowcount;  
  5.    dbms_output.put_line(to_char(var_count));  
  6. end;  

动态游标
定义
declare type emp_cur_type is ref cursor return emp%rowtype;

new_emp_cur_type emp_cur_type;

open new_emp_cur_type for select * from emp;

linux
相关资讯       Oracle教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款