Examine the data in the CUST_NAME column of the CUSTOMERS table.
CUST_NAME
———————
Lex De Haan
Renske Ladwig
Jose Manuel Urman
Jason Mallin
You want to extract only those customer names that have three names and display the * symbol in place of the
first name as follows:
CUST NAME
———————
*** De Haan
**** Manuel Urman
Which two queries give the required output? (Choose two.)
A.
SELECT LPAD(SUBSTR(cust_name, INSTR(cust_name, ‘ ‘)), LENGTH(cust_name), ‘*’) “CUST NAME”
FROM customers
WHERE INSTR(cust_name, ‘ ‘, 1, 2)<>0;
B.
SELECT LPAD(SUBSTR(cust_name, INSTR(cust_name, ‘ ‘)), LENGTH(cust_name), ‘*’) “CUST NAME”
FROM customers
WHERE INSTR(cust_name, ‘ ‘, -1, 2)<>0;
C.
SELECT LPAD(SUBSTR(cust_name, INSTR(cust_name, ‘ ‘)), LENGTH(cust_name)- INSTR(cust_name,
”), ‘*’) “CUST NAME”
FROM customers
WHERE INSTR(cust_name, ‘ ‘, -1, -2)<>0;
D.
SELECT LPAD(SUBSTR(cust_name, INSTR(cust_name, ‘ ‘)), LENGTH(cust_name)- INSTR(cust_name, ‘
‘), ‘*’) “CUST NAME”
FROM customers
WHERE INSTR(cust_name, ‘ ‘, 1, 2)<>0 ;
The SUBSTR(string, start position, number of characters) function accepts three parameters and returns a string consisting of the number of characters extracted from the source string, beginning at the specified start position:
image
The INSTR(source string, search item, [start position],[nth occurrence of search item]) function returns a number that represents the position in the source string, beginning from the given start position, where the nth occurrence of the search item begins:
image
SUBSTR(‘This is a test’, 6, 2)
Result: ‘is’
SUBSTR(‘This is a test’, 6)
Result: ‘is a test’
SUBSTR(‘TechOnTheNet’, 1, 4)
Result: ‘Tech’
SUBSTR(‘TechOnTheNet’, -3, 3)
Result: ‘Net’
SUBSTR(‘TechOnTheNet’, -6, 3)
Result: ‘The’
SUBSTR(‘TechOnTheNet’, -8, 2)
Result: ‘On’
Lpad:
LPAD(‘tech’, 7);
Result: ‘ tech’
LPAD(‘tech’, 2);
Result: ‘te’
LPAD(‘tech’, 8, ‘0’);
Result: ‘0000tech’
LPAD(‘tech on the net’, 15, ‘z’);
Result: ‘tech on the net’
LPAD(‘tech on the net’, 16, ‘z’);
Result: ‘ztech on the net’
A & B