Examine the data in the CUST_NAME column of the customers table.
You need to display customers’ second names where the second name starts with “Mc” or “MC.”
Which query gives the required output?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Explanation:
I think even B is not correct. It will select names starting with ‘mC’ or ‘mc’ as well which is not what the requirement is
WHERE (SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1,2)) IN (‘MC’,’Mc’);
The answer is based on the data shown. It’s correct.
B is the correct answer. The INITCAP function that is the outermost function will transform the name “MC” in “Mc”. Soon it will be possible to search for ‘Mc’ when using the LIKE function.
B is correct
B is not correct by 100% – but it’s the best answer… 😉
SQL> select substr(cust_name, instr(cust_name,’ ‘)+1)
2 from cust_q46
3 where initcap(substr(cust_name, instr(cust_name, ‘ ‘)+1)) like ‘Mc%’ ;
SUBSTR(CUST_NAME,INSTR(CUST_NAME,”)+1)
——————————————————————————–
McCain
MCEwen
SQL> select substr(cust_name, instr(cust_name,’ ‘)+1)
2 from cust_q46
3 where substr(cust_name, instr(cust_name, ‘ ‘)+1) like initcap(‘MC%’) ;
SUBSTR(CUST_NAME,INSTR(CUST_NAME,”)+1)
——————————————————————————–
McCain