--bulk into 的简单使用
--
declare
type emp_tab is table of emp%rowtype;
v_emp_tab emp_tab := emp_tab();
begin
select * bulk collect into v_emp_tab from emp;
if v_emp_tab is not empty then
for x in v_emp_tab.first .. v_emp_tab.last loop
dbms_output.put_line(v_emp_tab(x).empno || chr(9) || v_emp_tab(x)
.ename);
end loop;
else
dbms_output.put_line('v_emp_tab是空集合');
end if;
end;
/
--limit使用,退出循环方式1
--这种方式在第4次循环完就退出了。。
declare
type emp_tab is table of emp%rowtype;
v_emp_tab emp_tab := emp_tab();
cursor c_get_emp is
select * from emp;
v_count pls_integer :=0;
begin
open c_get_emp;
--limit子句只允许出现在fetch操作语句的批量中
loop
fetch c_get_emp bulk collect into v_emp_tab limit 10;
for x in 1 .. v_emp_tab.count loop
dbms_output.put_line(v_emp_tab(x).empno || chr(9) || v_emp_tab(x)
.ename);
end loop;
v_count:=v_count+1;
exit when c_get_emp%notfound;
end loop;
close c_get_emp;
dbms_output.put_line('赋值次数:'||v_count);
end;
/
--limit使用 退出循环方式2
--这种方式在第5次循环时退出
declare
type emp_tab is table of emp%rowtype;
v_emp_tab emp_tab := emp_tab();
cursor c_get_emp is
select * from emp;
v_count pls_integer :=0;
begin
open c_get_emp;
--limit子句只允许出现在fetch操作语句的批量中
loop
fetch c_get_emp bulk collect into v_emp_tab limit 10;
exit when v_emp_tab.count=0;
-- 或者使用 exit when v_emp_tab is empty;
for x in 1 .. v_emp_tab.count loop
dbms_output.put_line(v_emp_tab(x).empno || chr(9) || v_emp_tab(x)
.ename);
end loop;
v_count:=v_count+1;
end loop;
close c_get_emp;
dbms_output.put_line('赋值次数:'||v_count);
end;
/
--综上,第一种方式,稍微好点
bulk into 的简单使用
最新推荐文章于 2020-01-16 10:54:23 发布