declare
type tableType is table of emp%rowtype index by binary_integer;
v_emp tableType;
v_maxSal emp.sal%type;
i number(10);
begin
for v_dept in (select * from dept ) loop
select max(sal) into v_maxSal from emp where deptno=v_dept.deptno;
select * bulk collect into v_emp from emp where sal=v_maxSal;-----------------有疑问的地方
dbms_output.put_line('部门编号:'||v_dept.deptno);
dbms_output.put_line('========================');
if v_emp.count>0 then
for i in v_emp.first..v_emp.last loop
dbms_output.put_line(v_emp(i).ename||' '||v_emp(i).sal);
end loop;
else
dbms_output.put_line('该部门没有员工');
end if;
dbms_output.put_line('========================');
end loop;
end;
我注释的那一行中,去掉 bulk collect就出错了,虽然v_emp 是一个索引表(集合)类型,但是此条语句只是向v_emp 中插入了一条信息啊(loop每循环一次),为什么还一定要加上bulk collect呢?bulk collect
type tableType is table of emp%rowtype index by binary_integer;
v_emp tableType;
v_maxSal emp.sal%type;
i number(10);
begin
for v_dept in (select * from dept ) loop
select max(sal) into v_maxSal from emp where deptno=v_dept.deptno;
select * bulk collect into v_emp from emp where sal=v_maxSal;-----------------有疑问的地方
dbms_output.put_line('部门编号:'||v_dept.deptno);
dbms_output.put_line('========================');
if v_emp.count>0 then
for i in v_emp.first..v_emp.last loop
dbms_output.put_line(v_emp(i).ename||' '||v_emp(i).sal);
end loop;
else
dbms_output.put_line('该部门没有员工');
end if;
dbms_output.put_line('========================');
end loop;
end;
我注释的那一行中,去掉 bulk collect就出错了,虽然v_emp 是一个索引表(集合)类型,但是此条语句只是向v_emp 中插入了一条信息啊(loop每循环一次),为什么还一定要加上bulk collect呢?bulk collect
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货