游标PLSQL/SQL引撑切换在什么情况下发生?

客家族_Shark曾_小凡仙
博客专家认证
2012-07-31 09:53:37
只听说过使用游标会发生切换 所以采用批量BULK 方法
下面4种情况使用游标的方法 哪种会发生切换 还是全部分会发生切换?
1

Declare
Cursor myCur is select ename,job,sal,empno from emp;
varE myCur%rowType;
Begin
open myCur;
loop
fetch myCur into varE;
exit when myCur%notfound;
dbms_output.put_line(myCur%rowCount||' '||vare.empno||' '||vare.ename||' '||vare.sal);
end loop;
End


2

Declare
Cursor myCur is select * from emp;
varE myCur%rowType;
Begin
for varA in myCur
loop
select ename,job,sal,empno into varE from emp where empno= vara.empno;
dbms_output.put_line(vare.empno||' '||vare.ename||' '||vare.sal);
end loop;
End;


3
 
Declare
Cursor myCur is select ename,job,sal from emp;
type type_ename is table of emp.ename %type index by binary_integer;
type type_job is table of emp.job %type index by binary_integer;
type type_sal is table of emp.emp %type index by binary_integer;
l_ary_name type_ename;
l_ary_job type_job;
l_ary_sal type_sal;
Begin
open myCur;
loop
fetch myCur bulk collect into
l_ary_name,
l_ary_job,
l_ary_sal
limite 1;
exit when myCur%notfound;
dbms_output.put_line(myCur%rowCount||' '||l_ary_name(1)||' '||l_ary_job(1)||' '||l_ary_sal(1));
end loop;
End

4

Declare
Cursor myCur is select ename,job,sal from emp;
type type_ename is table of emp.ename %type index by binary_integer;
type type_job is table of emp.job %type index by binary_integer;
type type_sal is table of emp.emp %type index by binary_integer;
l_ary_name type_ename;
l_ary_job type_job;
l_ary_sal type_sal;
Begin
open myCur;
loop
fetch myCur bulk collect into
l_ary_name,
l_ary_job,
l_ary_sal
limite 1;
forall i in 1..l_ary_name.count
insert into table_b
(b.name,b.job,b.sal)
values(l_ary_name(i),l_ary_job(i),l_ary_sal(i))
exit when myCur%notfound;

end loop;
End
...全文
105 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
http://blog.chinaunix.net/space.php?uid=680758

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧