GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL

 Print  |  
Question:  Replace and Translate

Answer: How and in what way REPLACE is different from TRANSLATE?


March 03, 2009 02:09:29 #5
 sharmasl   Member Since: March 2009    Total Comments: 10 

RE: Replace and Translate
 

Translate check and replace character by character in the string like this
example-


SELECT TRANSLATE('AGDFADCDA ANLKAKE ABZUYA','AG','ZY') FROM DUAL;


here in all three words ('AGDFADCDA ANLKAKE ABZUYA') the character ‘A’ , ‘G’
and ‘AG’ are replace by character ‘Z’,’Y’ or ‘ZY’ . So the output is: -
ZYDFZDCDZ ZNLKZKE ZBZUYZ But in other hand Replace check and replace word by
word in the string like This example-


SELECT REPLACE ('AGDFADCDA ANLKAKE ABZUYA','AG','ZY') FROM DUAL;

Here in all three words ('AGDFADCDA ANLKAKE ABZUYA') only the first word where
‘AG’ came together is changed and remain word are same. It is because in other
words ‘AG’ not came together and replace can change words. So the output is: -
ZYDFADCDA ANLKAKE ABZUYA


Read it careful and try to understand.


Thanks

     

 

Back To Question