--3.查询10部门所有员工的姓名。(ref游标实现) 动态游标

declare

--创建一种游标类型

type type_cursor is ref cursor;

--声明变量指定游标类型

v_cur type_cursor;

v_ename emp.ename%type;

begin

open v_cur for select ename from emp where deptno=10;

loop

fetch v_cur into v_ename;

exit when v_cur%notfound;

dbms_output.put_line(v_ename);

end loop;

end;

--5.显示EMP中的第四条记录。 如:游标%rowcount=4

declare

cursor cur_emp is select * from emp;

v_emp emp%rowtype;

begin

open cur_emp;

loop

fetch cur_emp into v_emp;

exit when cur_emp%notfound;

if cur_emp%rowcount=4 then

dbms_output.put_line('姓名'||v_emp.ename);

end if;

end loop;

end;

/

--6.针对所有部门,按以下格式打印各部门人员姓名: 嵌套游标

部门名称:RESEARCH

部门人员:SMITH,JONES,FORD

部门名称: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;

最新文章

  1. LeetCode题解-----Wildcard Matching
  2. iOS---友盟推送遇到的坑
  3. JSONArray的使用
  4. css3写箭头
  5. Easyui CSS式样重写
  6. js 如何把JSON格式的字符串转换为JSON对象
  7. java对Ldap操作1
  8. 计算4000000000内的最大f(n)=n值---字符串的问题python实现(五岁以下儿童)
  9. 为什么你的Excel很丑?
  10. TortoiseGit安装与使用
  11. 关于在eclipse开发环境上打开手机data文件
  12. git提示错误关于错误:ssh: Could not resolve hostname github.com: Name or service not known.fatal: Could not read from remote repository.
  13. 华莱士的 第二个python程序之(格式化输出)
  14. keepalived实现mycat高可用问题排查;道路坎坷,布满荆棘,定让你大吃一惊!
  15. ActiveMQ 动态网络链接
  16. [转]【Angular4】基础(一):脚手架 Angular CLI
  17. css之absolute
  18. Channel L 自然拼读法 Teacher:Lamb
  19. MVC3学习:利用mvc3+ajax检测用户是否被注册
  20. P3302 [SDOI2013]森林

热门文章

  1. HDP3.1 中 YRAN 和 MR2 的内存大小配置的计算方式
  2. javascript基础工具清单
  3. Visual Studio 2017&C#打包应用程序详细教程,重写安装类获取安装路径
  4. winform中的Datagridview控件与List同步修改
  5. 转载 常用Jquery插件整理大全
  6. iphone手机QQ浏览器到底部继续上滑出现黑色背景盖住position:fixed的页面元素的问题
  7. Unity 动画系统目录
  8. DozerBeanMapper 配置
  9. python3+Appium自动化08-数据配置yaml
  10. hibernate log4j2输出sql带参数