2018.6.5 Oracle plsql编程 游标的使用
--3.查询10部门所有员工的姓名。(ref游标实现) 动态游标 --5.显示EMP中的第四条记录。 如:游标%rowcount=4 --6.针对所有部门,按以下格式打印各部门人员姓名: 嵌套游标 部门名称:ACCOUNTING 部门人员:CLARK,KING,MILLER,两种实现提示: 1)循环每个部门,用其部门号作条件去查员工表 2)用显示cursor完成 3)要求用FOR,会用到嵌套循环。 declare --控制部门名称的游标 cursor cur_dept is select dname from dept; --控制员工姓名的游标(作用:显示对应部门下的员工姓名)10,20,30 cursor cur_emp(v_dname dept.dname%type) is select ename from emp where deptno=(select deptno from dept where dname=v_dname); begin --外层循环控制cur_dept 游标(部门名称) for i in cur_dept loop dbms_output.put_line(‘=====部门名称=====‘||i.dname); --内层循环控制cur_emp游标(员工姓名) for j in cur_emp(i.dname) loop dbms_output.put_line(‘员工姓名‘||j.ename); end loop; end loop; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |