这个存储过程的作用是
把cust_grade_id='13'的cert_nbr的数据UPDATE 成
从1开始的依次增加1的数据
我执行存储过程后,怎么cert_nbr都变成了1 ,不是
1 2 3。。
哪位高手来指导一下

解决方案 »

  1.   

    if v_cert_nbr=1 then 
    ----------------------
             v_count:=1;
    --------------------------
              update wztest_2 set cert_nbr=v_count;
              commit;
             v_count:=v_count+1;
              end if ;
              end loop;-----------------------
    v_count:=1;的位置應該放在前面賽,因爲每次循環開始又被v_count:=1;了,當然不對。
    改爲        v_count:=1;if v_cert_nbr=1 then 
    就可以了哈! 
      

  2.   

    我改成了这样
    CREATE OR REPLACE PROCEDURE TEST1 IS  v_cert_nbr VARCHAR2(100);
      v_count    number;
      v_err_msg  varchar2(400);  CURSOR C1 IS
        SELECT cert_nbr 
          from wztest_2 ;
        begin
      v_count := 1;
      for rec in c1 loop
      
        begin
        
          select cert_nbr
            into v_cert_nbr
            from wztest_2
           where cust_grade_id = '13';
        exception
          when others then
            v_err_msg := SQLERRM;
        end;
        begin
        while  v_count < 10 loop
        
          update wztest_2 set cert_nbr = v_count
          where cert_nbr = rec.cert_nbr;
        dbms_output.put_line(v_count);
          commit;
        v_count := v_count + 1;    
        end loop;
        end ;  end loop;
    end TEST1;
    但是还是不行,打印出来的v_count的值上1,2,3,4,5,6,7,8,9
    但是UPDATE的值还都是2