View the Exhibit and examine the structure of the EMPLOYEES table.
Examine the data in the ENAME and HIREDATE columns of the EMPLOYEES table:
ENAME HIREDATE
——– —————-
SMITH 17-DEC-80
ALLEN 20-FEB-81
WARD 22-FEB-81
You want to generate a list of user IDs as follows:
USERID
————-
Smi17DEC80
All20FEB81
War22FEB81
You issue the following query:
SQL>SELECT CONCAT(SUBSTR(INITCAP(ename),1,3), REPLACE(hiredate,’-‘))
“USERID”
FROM employees;
What is the outcome?
A.
It executes successfully and gives the correct output.
B.
It executes successfully but does not give the correct output.
C.
It generates an error because the REPLACE function is not valid.
D.
It generates an error because the SUBSTR function cannot be nested in the CONCAT function.
Explanation:
REPLACE(text, search_string,replacement_string)
Searches a text expression for a character string and, if found, replaces it with a specified
replacement stringThe REPLACE Function
The REPLACE function replaces all occurrences of a search item in a source string with a
replacement term and returns the modified source string. If the length of the replacement term is
different from that of the search item, then the lengths of the returned and source strings will be
different. If the search string is not found, the source string is returned unchanged. Numeric and
date literals and expressions are evaluated before being implicitly cast as characters when they
occur as parameters to the REPLACE function. The REPLACE function takes three parameters,
with the first two being mandatory. Its syntax is REPLACE (source string, search item, [replacement
term]).
If the replacement term parameter is omitted, each occurrence of the search item is removed from
the source string. In other words, the search item is replaced by an empty string. .
The following queries illustrate the REPLACE function with numeric and date expressions:
Query 1: select replace(10000-3,’9′,’85’) from dual
Query 2: select replace(sysdate, ‘DEC’,’NOV’) from dual