2018.6.5 Oracle plsql编程 游标的使用
--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;
最新文章
- LeetCode题解-----Wildcard Matching
- iOS---友盟推送遇到的坑
- JSONArray的使用
- css3写箭头
- Easyui CSS式样重写
- js 如何把JSON格式的字符串转换为JSON对象
- java对Ldap操作1
- 计算4000000000内的最大f(n)=n值---字符串的问题python实现(五岁以下儿童)
- 为什么你的Excel很丑?
- TortoiseGit安装与使用
- 关于在eclipse开发环境上打开手机data文件
- git提示错误关于错误:ssh: Could not resolve hostname github.com: Name or service not known.fatal: Could not read from remote repository.
- 华莱士的 第二个python程序之(格式化输出)
- keepalived实现mycat高可用问题排查;道路坎坷,布满荆棘,定让你大吃一惊!
- ActiveMQ 动态网络链接
- [转]【Angular4】基础(一):脚手架 Angular CLI
- css之absolute
- Channel L 自然拼读法 Teacher:Lamb
- MVC3学习:利用mvc3+ajax检测用户是否被注册
- P3302 [SDOI2013]森林
热门文章
- HDP3.1 中 YRAN 和 MR2 的内存大小配置的计算方式
- javascript基础工具清单
- Visual Studio 2017&;C#打包应用程序详细教程,重写安装类获取安装路径
- winform中的Datagridview控件与List同步修改
- 转载 常用Jquery插件整理大全
- iphone手机QQ浏览器到底部继续上滑出现黑色背景盖住position:fixed的页面元素的问题
- Unity 动画系统目录
- DozerBeanMapper 配置
- python3+Appium自动化08-数据配置yaml
- hibernate log4j2输出sql带参数