Oracle Database SQL — Question 169
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(REPLACE(cust_last_name, ‘son’, ‘’), ‘An’, ‘O’) FROM customers;
- B. SELECT REPLACE(TRIM(TRAILING ‘son’ FROM cust_last_name), ‘An’, ‘O’) FROM customers;
- C. SELECT REPLACE(SUBSTR(cust_last_name, -3), ‘An’, ‘O’) FROM customers;
- D. SELECT INITCAP(REPLACE(TRIM(‘son’ FROM cust_last_name), ‘An’, ‘O’)) FROM customers;
Correct answer: A
Explanation
Option A is correct because it first removes 'son' from the last names and then replaces 'An' with 'O', resulting in 'Oder' for 'Anderson' and 'Aus' for 'Ausson'. Option B will not produce the desired output because TRIM does not have the intended effect on the string. Option C incorrectly uses SUBSTR which does not modify the string as required. Option D has a syntax error in TRIM and does not yield the correct transformations.