记忆-oracle游标

概要 

cursor 游标类型表示
%found SQL 语句影响了一行或多行时为 TRUE
%notfound SQL 语句没有影响任何行时为TRUE
%isopen  游标是否打开
%rowcount SQL 语句影响的行数
open 打开游标
close 关闭游标
fetch 取得游标的一行数据
open 游标名称 for   
游标名称 out sys_refcursor;  

举例

1

declare
  cursor rCursor is
    select * from tb2;
  vRow tb2%rowtype;
begin
  if rCursor%isopen then
    null;
  else
    open rCursor;
  end if;
  fetch rCursor
    into vRow;
  while rCursor%found loop
    dbms_output.put_line(rCursor%rowcount||' id:'||vRow.id);
      fetch rCursor
    into vRow;
  end loop;
  close rCursor;
end;

运行结果 

1 id:1
2 id:2
3 id:3
4 id:4
5 id:5
6 id:6
7 id:7
8 id:8
9 id:9
10 id:10
11 id:11
12 id:12

 tb2数据表

2 游标作为输出

create or replace procedure test_procedure3 (rCursor out sys_refcursor)
as
begin
  rCursor open for select * from tb2;
end;
发布了463 篇原创文章 · 获赞 38 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/xie__jin__cheng/article/details/103781587