正解:A,C
The provided SQL statement is an update statement that involves a subquery which is correlated to the main query.
A . The subquery is executed before the UPDATE statement is executed. (Incorrect) This statement is not accurate in the context of correlated subqueries. A correlated subquery is one where the subquery depends on values from the outer query. In this case, the subquery is executed once for each row that is potentially updated by the outer UPDATE statement because it references a column from the outer query (o.customer_id).
B . All existing rows in the ORDERS table are updated. (Incorrect)
Without a WHERE clause in the outer UPDATE statement, this would typically be true. However, the correctness of this statement depends on the actual data and presence of matching customer_id values in both tables. If there are rows in the ORDERS table with customer_id values that do not exist in the CUSTOMERS table, those rows will not be updated.
C . The subquery is executed for every updated row in the ORDERS table. (Correct) Because the subquery is correlated (references o.customer_id from the outer query), it must be executed for each row to be updated in the ORDERS table to get the corresponding cust_last_name from the CUSTOMERS table.
Reference:
D . The UPDATE statement executes successfully even if the subquery selects multiple rows. (Incorrect) The subquery inside the SET clause must return exactly one value for each row to be updated. If the subquery returns more than one row for any outer row, the UPDATE statement will result in an error (specifically, an "ORA-01427: single-row subquery returns more than one row" error).
E . The subquery is not a correlated subquery. (Incorrect)
This is incorrect because the subquery references the o.customer_id column from the ORDERS table, which makes it a correlated subquery.
The correct answers are A and C. The subquery is a correlated subquery because it references the ORDERS table's customer_id in its WHERE clause. It is executed for each row to be updated since it depends on values from the outer query (the o.customer_id). It's important to note that although the statement A is marked incorrect based on the typical behavior of correlated subqueries, in some cases, Oracle's optimizer may unnest the subquery and execute it beforehand if it determines that it's more efficient and the result is the same. However, this doesn't change the nature of the query being a correlated subquery.