set serveroutput on
--dbms_output.enable(1000000)
set serveroutput on size 10000
declare 
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值
很明显是 
update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode;
语句失效
但是该语句单独执行有效,就是将变量v_enttaxcode换成具体的值(这里是01037479)时有效
表cominfo中的e_enttaxcode的类型也是varchar2(50),所以不应该是变量的类型不匹配引起的,百思不得其解,还望大虾赐教,谢谢

解决方案 »

  1.   

    update tax.cominfo set iscalculate=0 where e_enttaxcode=v_enttaxcode;
    将这些更新放到自治事务中,在循环中调用改事务。
      

  2.   

    set serveroutput on
    --dbms_output.enable(1000000)
    set serveroutput on size 10000
    declare 
    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;
    /
      

  3.   

    你的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去掉修改下即可
      

  4.   

    谢谢二楼和三楼
    其实过程里所有语句都是有效的
    最要命的是我把
    [code=SQL]update cominfo set iscalculate=2 where e_taxadmin='陈云霞';[/SQL]
    放到循环里面去了,该语句很显然应该放在外面的
    真是太粗心了
      

  5.   

    一眨眼又有人回复了 呵呵
    to_四楼,我的本意是要替代游标。首先是
    update cominfo set iscalculate=2 where e_taxadmin='陈云霞';
    得到25条更新记录,也就是将计算标志位置成2。
    然后利用循环一条一条的将计算标志位IsCalculate置0
    结果如一楼,犯了个低级错误!