update t set f4=f3 where f3>100;

解决方案 »

  1.   

    楼主要求一一对应,而update t set f4=f3 where f3>100;这样的语句是错误的,因为如果f3>100的记录超过1条,那么F4到底赋与哪个F3的值呢?我也遇到这样的问题,最后拿存储过程搞的
      

  2.   

    update tab a
    set 字段4=(select 字段3 from tab b where a.rowid=b.rowid and 
               a.字段3>100); 1        111          2
     1        111        200        200
     1        111          2
     1        111        200        200
     1        111          2
     1        111        400        400
     1        111          3
      

  3.   

    不好意思,把自己的答案更正一下下啦:SQL> create table t(f1 varchar2(2),f2 varchar2(4),f3 integer,f4 integer);表已创建。SQL> begin
      2  insert into t values('01','0111',2,null);
      3  insert into t values('01','0111',200,null);
      4  insert into t values('01','0111',2,null);
      5  insert into t values('01','0111',200,null);
      6  insert into t values('01','0111',400,null);
      7  insert into t values('01','0111',30,null);
      8  commit;
      9  end;
     10  /PL/SQL 过程已成功完成。SQL> select * from t;F1 F2           F3         F4
    -- ---- ---------- ----------
    01 0111          2
    01 0111        200
    01 0111          2
    01 0111        200
    01 0111        400
    01 0111         30已选择6行。SQL> update t a
      2  set f4=f3
      3  where exists (select 1 from t b where b.rowid=a.rowid and b.f3>100);已更新3行。SQL> select * from t;F1 F2           F3         F4
    -- ---- ---------- ----------
    01 0111          2
    01 0111        200        200
    01 0111          2
    01 0111        200        200
    01 0111        400        400
    01 0111         30已选择6行。