首页 > 数据库DBA > oracle知识 > oracle_SQL >

多表关联的UPDATE 语句书写语法

作者: 初见博客 分类: oracle_SQL 发布时间: 2021-12-23 09:35

1、单表update

update 表名 set 列名=新值 where条件;

select语句 for update;
2、两表(多表)关联update — 仅在where字句中的连接

update table1 a — 使用别名
set a.type=’01’ –update值
where exists (select 1
from table2 b,table3 c
where b.user_id=a.user_id
and b.user_id=c.userid
)
3、两表(多表)关联update — 被修改值由另一个表运算而来

— update单个值
update table1 a
set a.name=(select b.name from table2 b where b.id=a.id)
where exists (select 1
from table2 b
where b.id=a.id
);

— update多个值
update customers a — 使用别名
set (name,type)=(select b.name,b.type
from table2 b
where b.id=a.id)
where exists (select 1
from table2 b
where b.id=a.id
);

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注