Replace function searches for a string and replaces with the given string. |
Translate function searches for a character and it replaces in occurrence of the character. |
REPLACE The Replace function replaces one value in a string with another. REPLACE (char,search_string,replace_string) If value for replace_string is not specify, the search_string value, when found, is removed. Possible input can be any character data types, like CHAR, VARCHAR2,NCHAR,CLOB. SELECT REPLACE('COMPUTER','OM','AB') Output |
TRANSLATE Translate does an orderly character-by-character substitution in a string. TRANSLATE (string,if,then) SELECT TRANSLATE(1256364,2345678,'BDEFGHI') |
The correct output is
ReplyDeleteSELECT TRANSLATE(1256364,2345678,'BDEFGHI')
FROM dual;
Output
----------
1BFGDGE
YES OUTPUT IS LIKE: 1BFGDGE
Deletecan we have more example of translate ?
ReplyDeleteSELECT
ReplyDelete'GANESH' STRING,
TRANSLATE('GANESH','GN','RM')TRANSLATE
FROM DUAL;
O/P:
STRING TRANSL
------ ------
GANESH RAMESH
EXPLANATION:
TRANSLATE('GANESH','GN','RM');
G=R,N=M
WHERE IS THE G IS THERE TRANSLATE TO R
WHERE IS THE N IS THERE TRANSLATE TO M GIVEN PATTERN.
best example ever...thanks
Delete