oracle 同时修改多条记录的多个字段

解决方案 »

  1.   

    update table set col1=value1,
                     col2=value2,
                     .....
                     coln=valuen
    where ....
      

  2.   

    update t1
    set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id)
    where t1.id=1234
    这样的???
      

  3.   

    http://www.cnblogs.com/samurai/archive/2007/09/25/905051.html你看下这个
      

  4.   

    2楼的写法是对的,不过好像不能一次修改多条.即后面的select查询出的数据大于1条时会出错
      

  5.   

    都对
    我都忘记oracle pl/sql了,2年没搞了.
      

  6.   

    如果修改where子句的限制条件呢?可以把需要更新的行都选择出来
    但保证每个t1.id和t2.id是一一对应的
      

  7.   

    where 有几条就更新几条,把where去了不就全更新了
      

  8.   

    update t1 
    set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) 
      

  9.   

    update t1 
    set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) 
    where exists
    (select 1 from t2 where t1.id=t2.id)
    存在的前提才更行
      

  10.   

    update t1 
    set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) 
    where exists 
    (select 1 from t2 where t1.id=t2.id) 同意这个,如果select t2会返回多行的话当然会报错
      

  11.   


    update test set id = 2, val = 'b'
    等同于
    update test set(id,val) = (select 2,'b' from dual)
      

  12.   

    update t1 
    set (col1, col2,col3,...) =(select val1,val2,val3,... from t2 where t1.id=t2.id) 
    where exists 
    (select 1 from t2 where t1.id=t2.id) 
      

  13.   

    lz理解错了,那个不能返回多条指的是对于t1的每一条记录只能对应t2的一条记录,否则会报返回多条的错误
    只要上面的条件满足了,那个sql是可以更新多条的