- SQL code
set serveroutput on--dbms_output.enable(1000000)set serveroutput on size 10000declare v_count int:=0;v_enttaxcode varchar2(50);begin loop update cominfo set iscalculate=2 where e_taxadmin='陈云霞';--满足这个条件的一共有24条记录 begin select e_enttaxcode into v_enttaxcode from tax.cominfo where iscalculate=2 and rownum<2; exception when others then null; end; if v_enttaxcode is not null then begin dbms_output.put_line(v_enttaxcode); end; else begin dbms_output.put_line('输出完毕'); exit; end; end if; update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode; select count(e_enttaxcode) into v_count from cominfo where iscalculate=2; dbms_output.put_line(v_count); v_enttaxcode:=null; end loop;end;/
运行之后,程序就进入死循环,
不停的打印
01037479
24
直到打印的数据行数超过 serveroutput size值
很明显是
- SQL code
update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode;
语句失效
但是该语句单独执行有效,就是将变量v_enttaxcode换成具体的值(这里是01037479)时有效
表cominfo中的e_enttaxcode的类型也是varchar2(50),所以不应该是变量的类型不匹配引起的,百思不得其解,还望大虾赐教,谢谢
------解决方案--------------------
update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode;
将这些更新放到自治事务中,在循环中调用改事务。
------解决方案--------------------
- SQL code
set serveroutput on--dbms_output.enable(1000000)set serveroutput on size 10000declare v_count int:=0;v_enttaxcode varchar2(50);begin loop--请问你加循环的作用是什么?并且该循环没有退出的条件(即:你说的死循环) update cominfo set iscalculate=2 where e_taxadmin='陈云霞';--满足这个条件的一共有24条记录 commit;--提交一下 begin select e_enttaxcode into v_enttaxcode from tax.cominfo where iscalculate=2 and rownum<2; exception when others then null; end; if v_enttaxcode is not null then begin dbms_output.put_line(v_enttaxcode); end; else begin dbms_output.put_line('输出完毕'); exit; end; end if; update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode; commit;--提交一下 select count(e_enttaxcode) into v_count from cominfo where iscalculate=2; dbms_output.put_line(v_count); v_enttaxcode:=null; end loop;--end;/
------解决方案--------------------
你的LOOP
END LOOP之间根本没有满足退出的条件,当然无限循环了
虽然你的if v_enttaxcode is not null then
begin
dbms_output.put_line(v_enttaxcode);
end;
else
begin
dbms_output.put_line('输出完毕');
exit;
end;
end if;
但是当v_enttaxcode 非空的时候就一直循环了,
而且你的查询只有得到一条记录select e_enttaxcode into v_enttaxcode from tax.cominfo where iscalculate=2 and rownum<2,为什么要循环?十分不解,把LOOP 和END LOOP去掉修改下即可