oracle中update多表关联查询
时间: 2023-11-17 18:06:56 浏览: 168
在Oracle中,可以使用子查询或MERGE语句实现多表关联更新。下面是两种实现方式的示例:
1. 使用子查询:
```sql
UPDATE table1
SET column1 = (SELECT column2
FROM table2
WHERE table1.key = table2.key),
column3 = (SELECT column4
FROM table3
WHERE table1.key = table3.key)
WHERE EXISTS (SELECT 1
FROM table2
WHERE table1.key = table2.key)
OR EXISTS (SELECT 1
FROM table3
WHERE table1.key = table3.key);
```
2. 使用MERGE语句:
```sql
MERGE INTO table1
USING (SELECT key, column2, column4
FROM table2
JOIN table3 ON table2.key = table3.key) t
ON (table1.key = t.key)
WHEN MATCHED THEN
UPDATE SET table1.column1 = t.column2,
table1.column3 = t.column4;
```
请根据你的具体需求选择适合的方式进行多表关联更新。
阅读全文