如何在ORACLE过程的游标中动态更新当前行?

解决方案 »

  1.   

    例如,在过程中定义游标:
    Cursor c1 is select col1,col2,col2 from table;
    ctype c1%rowtype;
    open c1;
    .....
    fetch c1 into ctype;如何更新ctype 中当前行?
      

  2.   

    不管是不是當前行,游標是駐留在內存里面的。
    而更新是針對數據庫的。
     open ...
     ...
     loop
        ...
        update ...
     end loop;
    ...
      

  3.   

    取出游标后,直接根据条件UPDATE不就行了。
    要实现什么效果?
      

  4.   

    declare
     
      v_numcredits  classes.num_credits%type;  
      cursor c_registeredstudents is
           select * from students
                   where id in (select student_id
                                  from registered_students
                                  where department= 'his'
                                  and course = 101)
           for update of current_credits;    -----
      // 还可以用wait n
      // select ... from... for update[of col_ref][wait n]
      // 等待n秒   数据行未解锁 就ora-54           for 9ibegin
      
      for v_studentinfo in c_registeredstudents loop
      
          select num_credits
                into v_numcredits
                from classes
                where department = 'his'
                and course = 101;  
          update students
                set current_credits = current_credits + v_numcredits
                where current of c_registeredstudents;   -------
      end loop;
      commit;
    end;
    /