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

海鲨数据库架构师:曾凡坤.姒 海鲨数据库架构师:曾凡坤.姒 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
只听说过使用游标会发生切换 所以采用批量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
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
海鲨数据库架构师:曾凡坤.姒
海鲨数据库架构师:曾凡坤.姒 领域专家: 数据库技术领域 领域专家: 数据库技术领域
Oracle 17,133 成员 55,258 内容