create or replace procedure test as    str_l_errmsg varchar2(3800);    --读取read_flag=1的所有记录
    cursor cur_headinfo is select id from table1 a where a.read_flag=1;    i_l_count  pls_integer;begin    update chdsc.edi_i_headinfo a set read_flag = 2 where read_flag = 1;    --循环读取cur_headinfo中信息
    for rec_hi in cur_headinfo loop
       begin
..........
       end;
    end loop;end test;

解决方案 »

  1.   

    create or replace procedure test as 
        str_l_errmsg varchar2(3800); 
        i_l_count  pls_integer; 
    begin 
        update chdsc.edi_i_headinfo a set read_flag = 2 where read_flag = 1; 
        --循环读取cur_headinfo中信息 
        for rec_hi in (select id from table1 a where a.read_flag=1) loop 
           ............
        end loop; 
    end test;前面定义的语句没啥用
      

  2.   

    你把满足游标的记录都给该了( 也就是将read_flag = 1都改成了 read_flag = 2),肯定进不去循环了,你如果把update chdsc.edi_i_headinfo a set read_flag = 2 where read_flag = 1; 
    去掉,进可以进了,游标是当他要用的时候才去读取表的
      

  3.   

    1.你所使用的是显式游标 所以要 open 和close 
    或者直接按照 for 变量 in (查询语句)loop end loop;
    这种就不需要定义游标啦 是隐式游标也不需要close和open2.你在游标读取前 已经把read_flag = 1的记录更新了  所以你读取的记录数是0