Oracle数据库(四)—— 光标

光标的属性和限制

/*
1、光标的属性
%found %notfound
%isopen 判断光标是否打开
%rowcount 受影响的行数
2、光标的限制
默认的情况下,oracle数据库只允许在同一个会话中,打开300个光标

打开SQL PLUS:输入show parameter cursor


修改光标数的限制:
alter system set open_cursors=400 scope=both;
scope的取值:both,memory,spfile(数据库需要重启).
{ memory:只更改当前实例不更改参数文件
spfile:只更改参数文件不更改当前实例
scope=spfile 仅仅更改spfile里面的记载,不更改内存,也就是不立即生效,而是等下次数据库启动生效。有一些参数只允许用这种方法更改
scope=memory 仅仅更改内存,不改spfile。也就是下次启动就失效了
scope=both 内存和spfile都更改
不指定scope参数,等同于scope=both.}
*/
set serveroutput on

declare
--定义光标
cursor c1 is select names,score from table1 ;
pname table1.names%type;
pscore table1.score%type;
begin
--打开光标
open c1;
loop
--取出一行的记录
fetch c1 into pname,pscore;
exit when c1%notfound;

dbms_output.put_line(pname||'的成绩为:'||pscore);
dbms_output.put_line('受影响的行数为:'||c1%rowcount);
end loop;
/*if c1%isopen then dbms_output.put_line('光标已经打开!');
else
dbms_output.put_line('光标没有打开!');
end if;*/
--关闭光标
close c1;

end;
/

带参数的光标

光标小案例

 

原文地址:https://www.cnblogs.com/myfaith-feng/p/7725544.html