SQLserver与Oralce中的两表关联更新是区别的。
在T-SQL中更新相对简单些,直接用下面的语句都是可以:
Update b
Set b.processflag = a.processflag
From temp_1 a Join temp_2 b
On a.msgid_db = b.msgid
Update temp_2
Set Usertime = b.Usertime
From temp_2 a Join temp_1 b
On a.msgid = b.msgid_db
Update temp_2
Set Usertime = b.Usertime
From temp_1 b
where msgid = b.msgid_db
而在Oracle中这样写是不对的,应该更改如下:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);
更新多个字段:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid),
a.processflag = (Select b.processflag
From Temp_1 b
Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);
多表关系更新:
Update Temp_2 a
Set a.Usertime = (Select b.Usertime
From Temp_1 b
Where b.Msgid_Db = a.Msgid),
a.processflag = (Select c.processflag
From Temp_3 c
Where c.Msgid = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid)
And Exists (Select 1 From Temp_3 c Where c.Msgid = a.Msgid);
感觉这点没sqlserver理简单易用~~~