plsql 将游标读取到table中
2024-08-27 15:03:56
-- 将游标中的数据 读取到table中 根据部门编号获得emp所有信息。
declare cursor c(no emp.deptno%type)is select * from emp where deptno=no; --1.定义游标 type emp_table_type is table of emp%rowtype index by binary_integer; --2.定义table
emp_table emp_table_type; --4.使用 table row1 emp%rowtype; --3.定义 rowtype
begin
open c(30); --输入部门编号
fetch c bulk collect into emp_table; --批量导入
for i in emp_table.first..emp_table.last -- for 循环便利 从table中的 first 到 last emp_table.first..emp_table.last
loop
dbms_output.put_line(
'cursor 编号'||i||
'------员工编号=='||emp_table(i).empno||
'------员工姓名=='||emp_table(i).ename
);
end loop;
close c;
end;
二、游标类型的变量 存储过程中当作参数使用;
--4、游标类型的变量 存储过程中当作参数使用; declare
type cur_type is ref cursor; --声明一个游标的类型 类似于 声明一个table的数据类型 1.声明 2.使用!
cur1 cur_type; -- 声明变量 使用变量。
row1 emp%rowtype;
begin
open cur1 for select * from emp; loop
fetch cur1 into row1;
exit when cur1%notfound;
dbms_output.put_line(
'----姓名=='||row1.ename||
'----工作=='||row1.job
); end loop; close cur1;
end;
三、使用for简化游标的操作
-- 5、使用for简化游标的操作
declare
cursor c is select * from emp; -- 定义游标
begin for row1 in c loop --row1 从游标中提取的一行数据 不需要定义直接用的啊? 或者说是 for循环自带定义功能
dbms_output.put_line( -- 直接循环 从前到后 不需要进行判断!
'姓名=='||row1.ename||
'---工资=='||row1.sal||
'-- cursor 角标=='||c%rowcount
);
end loop;
end;
最新文章
- mysql 卸载 linux
- 《JavaScript权威指南 第六版 中文版》(一)
- iOS resign code with App Store profile and post to AppStore
- Android源码学习之模板方法模式应用
- c#入门笔记(2)控件
- Spring触发器配置Quartz
- [Z] 计算机类会议期刊根据引用数排名
- [Nginx][HttpUpstreamModule]翻译负载均衡
- cf112a(水题)
- UVa 1149 (贪心) Bin Packing
- RHadoop教程翻译系列 _Mapreduce(1)_第一个Mapreduce任务
- ASPxGridView动态创建表格列编辑模板
- Linux守护进程的编程实现
- MCDownloader(iOS下载器)说明书
- 画布跟js.oop
- Python_驻留机制
- 一道题引出对LinkedList源码的研究
- [Mysql]MySQL 服务无法启动。
- H5 canvas控制坦克移动
- 教你使用markdown画程序流程图
热门文章
- 1065 - Number Sequence &;&;1070 - Algebraic Problem
- Decoupling Representation and Classifier for Long-tailed Recognition
- [算法笔记-题解]问题 B: 例题4-2 比较交换实数值
- 排列组合 ";n个球放入m个盒子m";问题 总结
- 开一场自己的特斯拉灯光秀「GitHub 热点速览 v.22.01」
- Java常用的开发库推荐
- Java数据类型 long 与 Long 的区别 和 正确用法
- js 动态设置键值对数组 ,类似于 java 的Map 类型
- Centos 7.6关闭selinux
- SYCOJ#111、吉祥物