Examine the data in the ename and hiredate columns of the employees table:
You want to generate a list of user IDs as follows:
You issue the following query:
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 string
The 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
response is C correct.
select concat(substr(initcap(‘ALLEN’),1,3), replace(’20-FEB-81′,’-‘)) as USERID
from dual
USERID
==========
All20FEB81
Read 1 rows
Sorry
Is option “A” is correct!!!!
A is correct
select replace(sysdate,’-‘) from dual;
170401
A : the correct answer