oracle动态游标

编程入门 行业动态 更新时间:2024-10-26 05:30:20

oracle动态<a href=https://www.elefans.com/category/jswz/34/1767796.html style=游标"/>

oracle动态游标

oracle动态游标  

无论显式还是隐式游标,获取记录集的查询定义在游标使用前必须确定。定义在整个生命周期内不可以修改,被叫作静态游标。 动态游标是指,在游标声明时,不指定其查询定义,而是在游标打开时进行定义。
一、强类型动态游标: 游标类型已经确定。
语法: type 游标类型 is ref cursor  return 记录类型 SQL> begin declare type employee_type is ref cursor return employees%rowtype; e_count number; employee employees%rowtype; cu_employee employee_type; begin select count(*) into e_count from employees where employee_position='项目经理'; if e_count=0 then open cu_employee for select * from employees; else open cu_employee for select * from employees where employee_position='项目经理'; end if; fetch cu_employee into employee; while cu_employee%found loop dbms_output.put_line(employee.employee_name || ':' || employee.employee_position); fetch cu_employee into employee; end loop; end; end;  / 王晓:开发经理 钟小平:高级工程师 刘俊:高级工程师 王龙:工程师 钟文:工程师 张三:测试工程师 李四:测试工程师 王五:测试工程师 Jamaly: Asha: MLing: ling:数据库工程师 二、弱类型动态游标: 没有指定返回类型。 语法: type 游标类型 is ref cursor 如:在表employees 中,如果无法获得项目经理的信息,则希望继续查询表managers 表以尝试在该表中获得项目经理。表的结构及数据如下所示。 MANAGER_ID MANAGER_NAME         MANAGER_POSITION ---------- -------------------- --------------------          1 张一民               财务经理          2 周波                 从事经理          3 刘永                 项目经理          4 王雪秋               项目经理 如: SQL> begin declare type custom_type is ref cursor; c_count number; employee employees%rowtype; manager managers%rowtype; cu_custom custom_type; begin select count(*) into c_count from employees where employee_position='项目经理'; if c_count=0 then open cu_custom for select * from managers where manager_position='项目经理'; fetch cu_custom into manager; while cu_custom%found loop dbms_output.put_line(manager.manager_name || ':' || manager.manager_position); fetch cu_custom into manager; end loop; else open cu_custom for select * from employees where employee_position ='项目经理'; fetch cu_custom into employee; while cu_custom%found loop dbms_output.put_line(employee.employee_name || ':' || employee.employee_position); fetch cu_custom into employee; end loop; end if; end; end; / 刘永:项目经理 王雪秋:项目经理 PL/SQL procedure successfully completed

更多推荐

oracle动态游标

本文发布于:2024-02-05 02:34:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1673449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游标   动态   oracle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!