Examine the data in the CUST_NAME column of the CUSTOMERS table.
CUST_NAME
————————Renske Ladwig
Jason Mallin
Samuel McCain
Allan MCEwen
Irene Mikkilineni
Julia Nayer
You need to display customers’ second names where the second name starts with “Mc” or “MC.”
Which query gives the required output?
A.
SELECT SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)
FROM customers
WHERE INITCAP(SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1))=’Mc’;
B.
SELECT SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)
FROM customers
WHERE INITCAP(SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)) LIKE ‘Mc%’;
C.
SELECT SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)
FROM customers
WHERE SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1) LIKE INITCAP(‘MC%’);
D.
SELECT SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)
FROM customers
WHERE INITCAP(SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)) = INITCAP(‘MC%’);
B
help ? : is ans. B for EBCDIC-based platform, and
ans. C(with INITCAP for SUBSTR) for ASCII platforms? , TY
The answer is B
with customers as(
select ‘Renske Ladwig’ as cust_name from dual UNION
select ‘Jason Mallin’ from dual UNION
select ‘Samuel McCain’ from dual UNION
select ‘Allan MCEwen’ from dual UNION
select ‘Irene Mikkilineni’ from dual UNION
select ‘Julia Nayer’ from dual
)
SELECT SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)
FROM customers
WHERE INITCAP(SUBSTR(cust_name, INSTR(cust_name,’ ‘)+1)) LIKE ‘Mc%’
/
SUBSTR(CUST_NAME,
—————–
MCEwen
McCain
by the way my platform is ASCII
🙂