Home  >  Article  >  Database  >  Oracle数据库中游标的使用

Oracle数据库中游标的使用

WBOY
WBOYOriginal
2016-06-07 17:32:211100browse

游标的定义: 游标的作用 在前面的文章中有提到过,查询结果如果超过一行,就需要使用游标。在文章rdquo;Oracle数据中的PL/SQL介

游标的定义:

游标的作用

在前面的文章中有提到过,查询结果如果超过一行,就需要使用游标。在文章”Oracle数据中的PL/SQL介绍“ 见 。

创建步骤:

定义一个游标

语法:CURSOR cursor_name is select _statement;

打开游标

语法:open cursor_name;

提取数据

使用fetch,fetch关键字会抓取当前行的记录,并将记录指针下移一行。就像JdbC中的ResultSet一样。

语法:fetch cursor_name into variable1,variable2.

游标的一些属性

关闭游标

语法:close cursor_name

示例代码如下:

普通的方法:

---游标的使用
declare
  --定义一个游标,,将tab_stu所有数据提取出来
 cursor c_tab_stu is
 select * from tab_stu;
 
 r_tab_stu tab_stu%rowtype;--使用rowtype存储游标数据
 
begin
  --打开游标
  open c_tab_stu;
  --提取数据
  fetch c_tab_stu into r_tab_stu;
  dbms_output.put_line('stu_id:'||r_tab_stu.stu_id);
  dbms_output.put_line('stu_name:'||r_tab_stu.stu_name);
  dbms_output.put_line('stu_age:'||r_tab_stu.stu_age);
  --关闭游标
  close c_tab_stu;
end;

接下来请看第2页精彩内容

 

相关阅读:

PL/SQL中三种游标循环效率对比

Oracle高级显式游标的使用

Oracle存储过程之insert的使用,含游标的使用

Oracle显示游标的使用详解

Oracle游标cursor简单使用

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn