既然已将游标做了fetch操作,直接修改into后面的变量值不就行了吗?为何要修改游标中某个字段的值?

解决方案 »

  1.   

    你的要求不能实现--不合法。
    如果你要更新表,使用update语句,如果你仅仅是取出值后要进行变化,必须使用变量。
      

  2.   

    好像可以在定义cursor用for update
    cursor cursor_name is select ... for update;
    ...
    update ... where current of cursor_name;
    ...
    commit;
    ...
      

  3.   

    使用for update不是去更新值的,而是加锁。
      

  4.   

    可以在定义游标时使用for update子句,这样在游标打开期间,事务结束之前,游标打开的表是一直被锁定的,此时,可以更新游标打开的表。一旦提交或回滚事务之后,锁被释放,fetch将非法
      

  5.   

    游标只能检索,不能更新,或者可以用检索到某个值的条件可以利用更新语句更新.
    loop
    fetch v_sor into 变量;
    exit when v_sor%notfound;
    .....
    update table_name set col_name=值 where id=v_sor.id;
    end loop;
      

  6.   

    更新游标不代表更新数据,这些楼上(beckhambobo)的都已经说过了.
    但是,游标可以象变量一样的来赋值,如下.
    open vCur_Line ;
       loop
          fetch vCur_Line into vRecord_Line;
       exit when vCur_Line%notfound or vCur_Line%notfound is null;
             vRecord_Line.C7 := null ;
             vRecord_Line.C8 := null ;
             vRecord_Line.C10 := null ;
             -- 此时vRecord_Line.C7 ,C8,C10都为null
        .....
        end loop;
    close vCur_Line;
      

  7.   

    在游标中update没问题,但是有commit时,可能会报错,好象是在816中没问题,但是在817中会出错的,oracle 的pdf文档中提到这个问题,即决方法是(记不太清了)
    用rowid定位
    cursor cursor_name is select a,b for update
    改为
    cursor cursor_name is select rowid as rid ,a,b for update;
    loop
    fetch cursor_name into 变量;
    exit when cursor_name%notfound;
    .....
    update table_name set col_name=值 where rowid=cursor_name.rid;
    (update table_name set col_name=值 where rowid=to_rowid(cursor_name.rid);  ?)
    end loop;