506629361 发表于 2018-9-14 09:44:16

oracle update用法

  注:update操作时,条件必须注意。不写where即为更新全表,不想更新的会被赋空值。
  单表更新:update tablename set col1=value where col2='value2';
  多表关联更新:update a set a.col1=(select b.col1 from b where a.col2=b.col2) where exists(select * from b where a.col2=b.col2); --exists条件必须要有,不然更新有误
  多字段更新:update a set (a.col1,a.col2) = (select b.col1,b.col2 from b where b.col3=a.col3 and b.col4=value2) where exists (select 1 from b where b.col3=a.col3 and b.col4=value2);--同样必须加条件,无where则为全表更新,不满足条件的为空。
  update a set a.col1=100   将所有行全部的特定列col1更新为特定值
  update a set a.col1=100 where a.col2
页: [1]
查看完整版本: oracle update用法