游标分类
显式游标:使用cursor语句显式定义游标,游标被定义后,需要打开并提取游标,关闭游标。
隐式游标:由oracle为每一个dml语句创建一个隐式游标也叫做SQL游标。
BEGIN
update emp
set comm = comm *1.12
where empno = 7346;
dbms_output.put_line(SQL%ROWCOUNT || '行被更新');--使用隐式游标
if sql%notfound --使用隐式游标
then
dbms_output.put_line('不能更新员工号为7346的员工');
end if;
commit;
end;
--由于隐式游标会自动关闭,因此SQL%isopen都是false.
declare
cursor emp_cursor (p_deptno in number) return emp%rowtype --定义游标并指定参数 和返回值
is
select * from emp where deptno = p_deptno;
begin
open emp_cursor(20);
end;
游标属性
%ISOPEN:判断对应的游标变量是否打开,如果打开则返回true否则返回false.
declare
cursor emp_cursor (p_deptno in number)
is
select * from emp where deptno = p_deptno;
begin
if not emp_cursor%isopen then open emp_cursor(20);
end if;
if emp_cursor%isopen then
dbms_output.put_line('游标已经被打开');
else
dbms_output.put_line('游标还未被打开');
end if;
close emp_cursor;
end;
%FOU
游标基本结构及属性(cursor)
最新推荐文章于 2024-09-16 23:21:21 发布
本文介绍了Oracle数据库中的游标,包括显式游标和隐式游标的概念与区别。通过示例展示了如何使用游标进行数据操作,并详细解释了游标的几个关键属性:%ISOPEN、%FOUND、%NOTFOUND和%ROWCOUNT,以及它们在游标操作中的作用。
摘要由CSDN通过智能技术生成