Oracle Database Administration I — Question 124
The CUSTOMERS table has a CUST_LAST_NAME column of data type VARCHAR2.
The table has two rows whose CUST_LAST_NAME values are Anderson and Ausson.
Which query produces output for CUST_LAST_NAME containing Oder for the first row and Aus for the second?
Answer options
- A. SELECT REPLACE(SUBSTR(cust_last_name, -3), 'An', 'O') FROM customers;
- B. SELECT REPLACE(TRIM(TRAILING 'son' FROM cust_last_name), 'An', 'O') FROM customers;
- C. SELECT INITCAP(REPLACE(TRIM('son' FROM cust_last_name), 'An', 'O')) FROM customers;
- D. SELECT REPLACE(REPLACE(cust_last_name, 'son', ''), 'An', 'O') FROM customers;
Correct answer: D
Explanation
The correct answer is D because it first removes 'son' from both last names and then replaces 'An' with 'O', resulting in 'Oder' for Anderson and 'Aus' for Ausson. Option A incorrectly uses SUBSTR, which does not correctly manipulate the strings as required. Option B fails to produce the desired output because it only trims 'son' from the end without addressing the 'An' replacement properly. Option C is incorrect as it uses INITCAP and a wrong TRIM syntax that does not achieve the intended result.