您的位置:首页 > 数据库 > Oracle

oracle游标的例子

2014-04-30 00:00 441 查看
摘要: oracle

declare
cursor ca is
select id_no, name from user where ym=201401;
begin
for cb in ca loop
update path set ename=cb.name where id_no=cb.id_no;
end loop;
commit;
end;


-------------

declare
--游标结构
cursor ca is select * from emp where deptno = 10;
--游标变量
carec ca%rowtype;
begin


-----------------

declare
--游标结构
cursor ca is select * from emp where deptno = 10;
--游标变量
onerow ca%rowtype;
begin
--打开游标
open ca;
loop
fetch ca into onerow;
exit when ca%notfound;
dbms_output.put_line(onerow.ename);
end loop;
close ca;
end;


-------------

declare
cursor ca(dno emp.deptno%type) is select * from emp where deptno = dno;
carec ca%rowtype;
begin
for carec in ca(10) loop
dbms_output.put_line(carec.ename);
end loop;
end;


--动态游标

declare
--动态游标数据类型
type cur is ref cursor;
--游标结构变量
mycur cur;
--行变量
cdept dept%rowtype;
cemp emp%rowtype;
begin
--动态游标绑定select * form dept;
open mycur for select * from dept;
loop
fetch mycur into cdept;
exit when mycur%notfound;
dbms_output.put_line(cdept.dname);
end loop;
dbms_output.put_line('--------------------------------');
open mycur for select * from emp;
loop
fetch mycur into cemp;
exit when mycur%notfound;
dbms_output.put_line(cemp.ename);
end loop;
close mycur;
end;


建议你百度.google吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 游标