declarecursor c1(v_dept_no number)
is select deptno,maxsal from test_s where deptno=v_dept_no;
begin
for c1_rec in c1(30)
loop
--dbms_output.put_line('c1:'||c1_rec.deptno||''||c1_rec.maxsal );
insert into test_s( deptno,maxsal)
select deptno,maxsal from test_s;
end loop;end;
有人能详细解释一下,上面写的是什么意思吗?
为什么`test_s表里有2条记录时,再执行时会跑出``多6条记录呢```不太明白这个思路``~!c1_rec 也是游标??
is select deptno,maxsal from test_s where deptno=v_dept_no;
begin
for c1_rec in c1(30)
loop
--dbms_output.put_line('c1:'||c1_rec.deptno||''||c1_rec.maxsal );
insert into test_s( deptno,maxsal)
select deptno,maxsal from test_s;
end loop;end;
有人能详细解释一下,上面写的是什么意思吗?
为什么`test_s表里有2条记录时,再执行时会跑出``多6条记录呢```不太明白这个思路``~!c1_rec 也是游标??
select deptno,maxsal from test_s;
这句话会是你的test_s记录数加倍
你开始是两条
循环一次后加倍变成4条
再循环一次再次加倍变成8条8-2=6
6条就这么出来的吧
用来loop 循环insert into test_s( deptno,maxsal)
select deptno,maxsal from test_s; 又是往同一个表中插入数据
循环后相当:2(原有)+2(第一次loop)+4(第二次loop)
共插入6条记录
把给定dept_no的部门的记录找出来,再插入到该表中,然后选出来,没有commmit也没有rollback,可能会造成锁的问题