- 浏览: 123445 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
miniduan:
i here by provide one that work ...
python 文件插入第一行 -
miniduan:
验证了一下,不好用啊:import fileinput, os ...
python 文件插入第一行
游标是构建在L/SQL中用来查询数据库、获取记录集合(结果集)的指针,它使开发人员能够一次访问一行结果集。为了处理SQL语句,Oracle将在内存中分配一个区域,这就是上下文区。这个区包含了已经处理完的行数、指向被分析语句的指针,整个区是查询语句返回的数据行集。游标就是指向上下文区句柄或指针。两种游标:
- 显示游标:显示游标被用于处理返回多行数据的SELECT语句,游标名通过CURSOR….IS 语句显示地赋给SELECT 语句。在PL/SQL中处理显示游标所必需的四个步骤:
- 声明游标:
CURSOR cursor_name IS select_statement
- 打开游标:
OPEN cursor_name
- 取得结果放入PL/SQL变量中:
FETCH cursor_name INTO list_of_variables; FETCH cursor_name INTO PL/SQL_record;
- 关闭游标:
CLOSE cursor_name
注意:在声明游标时,select_statement不能包含INTO子句。当使用显示游标时,INTO子句是FETCH语句的一部分。
- 声明游标:
- 隐式游标:所有的隐式游标都被假设为只返回一条记录。使用隐式游标时,用户无需进行声明、打开及关闭。PL/SQL隐含地打开、处理,然后关掉游标。
四种常用的游标例子:
- FOR循环游标:
declare -- 类型定义 cursor my_cursor is select empno,ename,job,sal from emp where job = 'MANAGER'; begin -- for 循环 for cursor_record in my_cursor loop dbms_output.put_line(cursor_record.empno||'-'||cursor_record.ename ||'-'||cursor_record.job||'-'||cursor_record.sal); end loop; end;
- Fecth游标:
/* * Fetch游标 */ declare -- 类型定义 cursor my_cursor is select empno, ename, job, sal from emp where job = 'MANAGER'; -- 定义一个游标变量 l_cursor my_cursor%rowtype; begin -- 打开游标 open my_cursor; -- loop循环 loop -- 提取一行数据到l_cursor变量中 fetch my_cursor into l_cursor; exit when my_cursor%notfound; dbms_output.put_line(l_cursor.empno||'-'||l_cursor.ename|| '-'||l_cursor.job||'-'||l_cursor.sal||'-'||my_cursor%rowcount); end loop; -- 关闭游标 close my_cursor; end;
游标的4种属性:- %notfound fetch是否提到数据 没有true 提到false
- %found fetch是否提到数据 有true 没提到false
- %rowcount 已经取出的记录的条数
- %isopen 布尔值 游标是否打开
- 参数游标:
/* * 参数游标 */ declare -- 获得部门 cursor my_cursor1 is select deptno from dept; -- 定义游标参数,只能指定类型,不能指定长度 cursor my_cursor2(no number, pjob varchar2) is select emp.* from emp where deptno = no and job = pjob; begin for cursor_record1 in my_cursor1 loop -- 参数在游标中使用 for cursor_record2 in my_cursor2(cursor_record1.deptno, 'MANAGER') loop dbms_output.put_line(cursor_record2.deptno || '-' || cursor_record2.ename); end loop; end loop; end;
- 引用游标/动态游标:
/* * 引用游标/动态游标 */ declare -- 定义一个弱类型的ref cursor type weakly_cursor is ref cursor; -- 定义一个强类型的ref cursor type strongly_cursor is ref cursor return dept%rowtype; -- 定义ref cursor类型的变量 w_cursor weakly_cursor; s_cursor strongly_cursor; -- 定义记录 emp_record emp%rowtype; dept_record dept%rowtype; begin dbms_output.put_line('输出员工'); open w_cursor for select * from emp; loop fetch w_cursor into emp_record; exit when w_cursor%notfound; dbms_output.put_line(emp_record.ename); end loop; close w_cursor; dbms_output.put_line('输出部门'); open s_cursor for select * from dept; loop fetch s_cursor into dept_record; exit when s_cursor%notfound; dbms_output.put_line(dept_record.dname); end loop; close s_cursor; end;
发表评论
-
mysql 5.7.14-winx64 安装
2016-08-22 22:40 474下载,解压 bin目录增加入path变量 管理员身份启动 ... -
toad 未安装oracle客户端 配置
2013-11-15 11:08 14611. 下载toad软件和oracle的instantcli ... -
linux oracle 12514错误解决办法
2013-07-30 17:34 1779解决方法: 1. 打开<OracleHome> ... -
ora-00054:resource busy
2013-07-24 16:26 839当某个数据库用户在数据库中插入、更新、删除一个表的数据,或 ... -
Oracle 启动
2013-07-03 09:57 663$ su - oracle $ sqlplus / as ... -
sqlserver字符串拆分(split)方法汇总
2012-05-15 13:58 919--方法0:动态SQL法 declare @s varcha ... -
sql server 索引简介
2012-04-01 17:29 887什么是索引 拿汉语字典的目录页(索引)打比方 ... -
T-SQL之SET ANSI_NULLS
2012-03-21 14:20 941当 SET ANSI_NULLS 为 ON 时 ... -
sqlserver 获得外键关联表名
2012-03-14 18:59 1700获取表修改时间:SELECT modify_date FR ... -
sql server 查询表名,列名等
2012-03-14 18:23 4484--1:获取当前数据库中的所有用户表 select Name ... -
连接mysql和 建索引花费
2012-02-07 10:23 910mysql -h192.168.0.150 -uroot -p ... -
查询乱码和按月查询
2012-01-04 15:29 894SET character_set_connection=ut ... -
PL/SQL 控制语句
2011-12-01 11:04 829条件语句: if...then...else语句: dec ... -
Oracle 集合 方法
2011-11-30 11:22 741The COUNT Method: 用于计算 associa ... -
oracle 集合
2011-11-29 17:07 606记录(Record): 由单行多 ... -
oracle PL/SQL 标量数据类型
2011-11-28 18:17 1165字符数据类型: 类型名称 描述 char ... -
oracle 情景查询
2011-11-25 14:26 729decode()函数: 类似于if ... then ... ... -
Oralce 层次查询
2011-11-25 14:00 665初始化数据库,创建表和导入数据:create tab ... -
Oracle 时间和字符串的装换
2011-11-24 16:33 902使用to_char()函数可以完成从日期数据到字符串的准换过 ... -
Pl/SQL Developer 常用技巧
2011-11-24 10:55 654PL/SQL Developer记住登陆 ...
相关推荐
oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结oracle游标的总结
Oracle游标的一般使用
oracle游标使用大全,详细描述了如何使用游标,创建游标等等
ORACLE 游标使用示例,给大家可以共享一下。
Oracle游标使用方法及语法大全.doc
详细的oracle游标用法,简单易懂,是学习游标的好材料
oracle 游标FOR循环
Oracle游标使用方法及语法大全
oracle游标 详解 精析 示例 真正能把游标讲透、说全、调理清晰的讲义。 游标犹如C语言的指针:灵活、实用、高效。 游标实际上是一种能从包括多条数据记录的结果集中每次提取一条记录的机制。 游标是一个通过定义...
oracle游标优化以及oracle游标的作用和游标的概念。
oracle游标使用大全,其中有很多例子,有助于大家理解,希望对初学者有帮助
详细介绍了 oracle的游标使用 及 实例
Oracle 游标! 值得下载看看!资源免费,大家分享!!
关于游标使用问题的练习附答案。游标分隐式和显示游标;动态和ref游标。。。
游标是存储过程最基本的要会的,用于访问 ORACLE 数据库的 DDL 和 TCL 语
主要描述oracle中游标的学习隐式游标和显示游标
该资源系本人培训期间的关于ORCL 游标所有实用案例,在此共享希望对大家学习有所帮助
我自己编写的oracle游标案例,希望对大家有点帮助!