QuestionQ87

VerifiedManipulating Data

EMPLOYEES and DEPARTMENTS data:

EMPLOYEES

Question Image

DEPARTMENTS

Question Image

In the EMPLOYEES table, EMPLOYEE_ID is the primary key. MGR_ID is the manager ID and refers to EMPLOYEE_ID.

In the DEPARTMENTS table, DEPARTMENT_ID is the primary key.

Evaluate this UPDATE statement.

UPDATE employees  
SET mgr_id =  
  (SELECT mgr_id  
   FROM employees  
   WHERE dept_id =  
     (SELECT department_id  
      FROM departments  
      WHERE department_name = 'Administration')),  
  salary =  
    (SELECT salary  
     FROM employees  
     WHERE emp_name = 'Smith')  
WHERE job_id = 'IT_ADMIN';  

What occurs when the statement is executed?

Explanation

A scalar subquery used as an expression must return no more than one row. The salary subquery for EMP_NAME = 'Smith' returns two rows—one for employee ID 101 and one for employee ID 106—so Oracle raises a single-row-subquery error and the UPDATE fails. Oracle Database: Scalar Subquery Expressions

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!