Oracle学习笔记——在PL/SQL使用游标获取数据
来源:互联网 发布:c语言定义变量 编辑:程序博客网 时间:2024/06/05 03:58
oracle不允许定义数组,查找出来的数据是一个大集合的话就需要使用游标进行遍历打印
隐式游标
例子:遍历emp表中员工,打印员工的名字和薪水
declare-- 静态游标 游标指向结果集 cursor test_cursor is select * from emp;row_info emp%rowtype;begin -- 打开游标 open test_cursor; loop fetch test_cursor into row_info; -- 赋值 exit when test_cursor%notfound; dbms_output.put_line(row_info.ename|| row_info.sal); end loop; close test_cursor;end;
结果:
例子二;
/* 查询员工表中 工资 超过4000 的员工 信息, 如果他所在的是市场部门,那么他的工资减少10%;*/declare cursor info_cursor is select empno,sal,dname from emp,dept where emp.deptno = dept.deptno; v_empno number(4); v_sal number(7,2); v_dname varchar2(50);begin open info_cursor; loop fetch info_cursor into v_empno,v_sal,v_dname; exit when info_cursor%notfound; if v_sal>4000 and v_dname='ACCOUNTING' then update emp set sal =sal-sal*0.1 where empno = v_empno; commit; end if; end loop; close info_cursor;end;
动态游标
-- 动态游标declare-- 声明一个 引用游标 type cursor_type is ref cursor; -- 声明引用游标变量 emp_cursor cursor_type; emp_info emp%rowtype;begin-- 打开游标 并 指向sql open emp_cursor for select * from emp; loop fetch emp_cursor into emp_info; exit when emp_cursor%notfound; dbms_output.put_line(emp_info.ename); end loop; close emp_cursor;end;
效果:
- Oracle学习笔记——在PL/SQL使用游标获取数据
- [Oracle]在PL/SQL中更改数据和使用游标获取数据
- Oracle数据库编程:在PL/SQL中使用游标获取数据
- Ch5 PL/SQL使用游标获取数据
- PL/SQl使用游标获取数据
- ORACLE PL/SQL游标(cursor)学习笔记
- Oracle 学习笔记 16 -- 游标(PL/SQL)
- Oracle学习笔记(5) 在PLSQL中使用游标获取数据
- Oracle学习笔记(第五章) 在PLSQL中使用游标获取数据
- Oracle 学习:PL/SQL循序渐进全面学习教程--课程十三 使用组合数据类型* 游标操纵数据
- Oracle 学习:PL/SQL循序渐进全面学习教程--课程十三 使用组合数据类型* 游标操纵数据
- 5.PL/SQL中使用游标获取数据
- 【Oracle】PL/SQL——游标CURSOR
- pl SQL 学习笔记(五)oracle 游标
- Oracle笔记 九、PL/SQL 游标的使用
- Oracle笔记 九、PL/SQL 游标的使用
- Oracle笔记 九、PL/SQL 游标的使用
- Oracle笔记 九、PL/SQL 游标的使用
- bcp命令详解
- 第100章、WebView应用之Javascript调用Android(从零开始学Android)
- 函数
- Matlab编程随笔:GUI的fig文件重命名
- java学习小心得(SSH)
- Oracle学习笔记——在PL/SQL使用游标获取数据
- Ti ducati 一个codec问题的记录
- friends105. The One with the East German Laundry Detergent
- 入门级ARM汇编指令
- UI设计准则
- 指针的一些看法
- 在UITableView中动态的插入或删除行(或者节)
- 时间类
- Android学习:不再提示对话框(创建自定义对话框)