-
使用多列子查询进行更新——SQL语言入门知识
资源介绍
用多列子查询进行修改
*
SQL> UPDATE emp
2 SET (job, deptno) =
3 (SELECT job, deptno
4 FROM emp
5 WHERE empno = 7499)
6 WHERE empno = 7698;
1 row updated.
更改第 7698号雇员的工作和部门,以与第 7499号雇员进行匹配.
*
UPDATE emp
SET (job, deptno) =
(SELECT job, deptno FROM emp WHERE empno = 7499)
WHERE empno = 7698;
Updating Rows with a Multiple-Column Subquery
Multiple-column subqueries can be implemented in the SET clause of an UPDATE statement.
Syntax
Instructor Note
It may be worth showing participants that the results would be the same for the example on the slide if two different subqueries were used in the SET clause as illustrated below:
SQL> UPDATE emp
2 SET job = (SELECT job FROM emp
3 WHERE empno = 7499),
4 deptno = (SELECT deptno FROM dept
5 WHERE dname = 'SALES')
6 WHERE empno = 7698;
UPDATE table
SET (column, column, ...) =
(SELECT column, column, ...
FROM table
WHERE condition)
WHERE condition;
- 上一篇: 缺省选项-SQL语言基础
- 下一篇: Oracle数据库中的表-SQL语言基础