nbsp; FROM a c WHERE c.c4 <> 0);
4 Rows updated in 0 seconds
select * from a; C1 C2 C4 ---------- ---------- 9 a1 0 9 a2 2 9 a3 3 9 a8 4
## 表自己对自己更新 示例5 UPDATE a d SET (d.c1) = (SELECT SUM(c.c4) FROM a c WHERE c.c4 <> 0) WHERE d.c4 = 0;
1 Rows updated in 0 seconds
select * from a; C1 C2 C4 ---------- ---------- 9 a1 0 2 a2 2 3 a3 3 8 a8 4
## 表更新表 示例6 UPDATE A SET A.c2 =B.c3 from A ,B where A.c1=B.c1;
ORA-00933:
SQL命令未正确结束
## 表更新表 示例7 update a set a.c2 = (select b.c3 from b where a.c1=b.c1);
4 Rows updated in 0 seconds
select * from a; C1 C2 C4 ---------- ---------- 1 b1 0 2 b2 2 3 b3 3 8 4
## 表更新表 示例8 update a set a.c2 = (select b.c3 from b where a.c1=b.c1) where exists (select 1 from b where a.c1=b.c1);
3 Rows updated in 0 seconds
select * from a; C1 C2 C4 ---------- ---------- 1 b1 0 2 b2 2 3 b3 3 8 a8 4
分析与说明: 1、
SQL Server和
Oracle的update语法有所区别共同点1:update后只能跟一个表共同点2:SQL Server和
Oracle的update语法都可以用如下方式实现多表更新 UPDATE updatedtable SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...] FROM srctable [WHERE where_definition])
不同点:SQL Server的update语句中from后可跟多个表
,Oracle则不支持该用法
2、示例2、示例4和示例7的用法都不严谨
,缺少条件将导致无可挽回的损失正确的用法应该为示例3、5和8 请仔细对比
。以上示例都是在原始数据基础上进行的,每个示例用的原始数据都相同
。