oracle与mssql语法差异 2.update from

2609阅读 0评论2007-11-06 zhongtang
分类:Oracle

关键词: oracle mssqlserver 语法差异 update
 
case 2. update from
 
tablea
(
  cola int,
  colb varchar(20),
  colc varchar(50)
)
 
tableb
(
  col1 int ,
  col2 varchar(20) ,
  col3 varchar(50)
)
 
现在要根据tableb修改tablea数据。
 
在mssql中语法:
update tablea
   colb = b.col2 , colc=b.col3
from tablea a ,tableb b
where a.cola = b.col1
 
在oracle语法:
update tablea
set (colb,colc)= (select col2,col3 from tableb where b.col1= a.cola )
where exists(
          select 1 from tableb where b.col1=a.cola )
 
注意:后面的exists必须有,要不然就是整个tablea表的所有记录都被修改,不满足条件的记录直接置成null
 
<------------- end ------------->
上一篇:oracle与mssql语法差异 1.select into
下一篇:水调歌头 牛市几时有