Correlated Subqueries

A correlated subquery is a subquery that is executed for each row of the base table. An example of a correlated subquery in a WHERE clause is shown here:

UPDATE emp e
SET e.deptno = (SELECT deptno FROM dept WHERE dname = 'SALES')
WHERE NOT EXISTS
(SELECT 'X' FROM dept d
WHERE  e.deptno = d.deptno);

In this example, all employees that do not have a department are assigned to the Sales department. The key characteristic of a correlated subquery is that it is called for each row retrieved.

Get Oracle Database Administration: The Essential Refe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.