GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  Basics
Go To First  |  Previous Question  |  Next Question 
 Basics  |  Question 17 of 49    Print  
What is the Difference between Replace and Translate

  
Total Answers and Comments: 9 Last Update: April 09, 2009     Asked by: Srinu 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Saumendra Mohanty
 

Both Replace and Translate are single row functions in Oracle 9i.

The Replace Function replaces single character with multiple characters.

But in Translate Function replaces sinlge character with sinlge character only.



Above answer was rated as good by the following members:
sreddy_bond, sumisusan, subajay, ds_devi
March 24, 2006 00:11:07   #1  
gomathi.e        

RE: What is the Difference between Replace and Transla...

replace chages the record in database.

but translate won't change it the database content is not changed


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 24, 2006 02:28:33   #2  
meetnaveen4u Member Since: March 2006   Contribution: 14    

RE: What is the Difference between Replace and Transla...
Replace used for String and Translate used for Character
 
Is this answer useful? Yes | No
May 16, 2006 15:26:07   #3  
Saumendra Mohanty        

RE: What is the Difference between Replace and Transla...

Both Replace and Translate are single row functions in Oracle 9i.

The Replace Function replaces single character with multiple characters.

But in Translate Function replaces sinlge character with sinlge character only.


 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
September 14, 2006 10:30:59   #4  
oradev03 Member Since: September 2006   Contribution: 2    

RE: What is the Difference between Replace and Transla...

TRANSLATE function:

Translate function does character by character substitution in a string

format- TRANSLATE(STRING IF THEN)

Translate looks at each character in 'STRING' and then check 'IF' to see if that character is there if it is there then it notes the position in 'IF' where it found the character and then looks the same position in 'THEN'

for example-1. SELECT TRANSLATE(7671234 234567890 'BCDEFGHIJ') FROM dual;

Result of the query above is- GFG1BCD

2. SELECT TRANSLATE('NOW VOWELS ARE UNDER ATTACK' 'TAEIOU' 'Taeiou') FROM dual;

Result- NoW VoWeLS aRe uNDeR aTTaCK

this feature of TRANSLATE ability to eliminate characters from a string can prove very useful in cleaning up data.

one more example

SELECT amountchar TRANSLATE(amountchar '1 $' '1') FROM comma;

result:

AMOUNTCHAR TRANSLATE(AMOUNTCHAR....)

$0 0

$0.25 0.25

$1.25 1.25

$12.25 12.25

$1 234.25 1234.25

3. SELECT AMOUNTCHAR TRANSLATE(AMOUNTCHAR ' s' ' ') FROM dual;

AMOUNTCHAR TRASLATE(AMOUNTCHAR' '')

$0

$0.25

$1.25

$12.25

Without at least one real character in the 'THEN' TRANSLATE produces nothing.

------------------------------------------------------------------------

REPLACE

REPLACE function replaces a character or characters in a string with zero or more charcters

REPLACE('ADAH' 'A' 'BLAH')

this evaluate the string 'ADAH'.

Everywhere an 'A' is found it will be replaced with a string 'BLAH'

so the result will be- BLAHDBLAHH

2.REPLACE('GEORGE' 'GE' NULL)

result- OR

---- Courtesy: Oracle Complete Reference Book


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 12, 2008 15:12:44   #5  
dl_mstr Member Since: November 2007   Contribution: 26    

RE: What is the Difference between Replace and Translate
Translate replaces by position the first character of the list to match is replaced by the first character of the replacement list. The second character with the second and if there are characters in the list to match that do not have positional equivalents in the replacements list they are dropped.
Replace replaces the string to match with the replacement string. The replacement of a single character is the same as that of TRANSLATE.

 
Is this answer useful? Yes | No
February 12, 2008 15:13:52   #6  
dl_mstr Member Since: November 2007   Contribution: 26    

RE: What is the Difference between Replace and Translate
Translate replaces by position the first character of the list to match is replaced by the first character of the replacement list. The second character with the second and if there are characters in the list to match that do not have positional equivalents in the replacements list they are dropped.

Replace replaces the string to match with the replacement string. The replacement of a single character is the same as that of TRANSLATE.

For Example:

SQL> SELECT translate('So What' 'o' 'ay')
2 FROM dual;

TRANSLATE
-------
Sa What

SQL> SELECT REPLACE('So What' 'o' 'ay')
2 FROM dual;

REPLACE
--------
Say What

 
Is this answer useful? Yes | No
May 27, 2008 06:05:26   #7  
ashishdixit Member Since: May 2008   Contribution: 5    

RE: What is the Difference between Replace and Translate
below is an eg showing the difference

SQL> select replace('missisippi' 'is' '12') replace translate('missisippi' 'is' '12') translate from dual;

REPLACE TRANSLATE
---------- ----------
m12s12ippi m122121pp1

hope it clarifies the doubt!

 
Is this answer useful? Yes | No
September 23, 2008 06:57:12   #8  
rkhreddy Member Since: September 2008   Contribution: 1    

RE: What is the Difference between Replace and Translate
if we write query like this using traslate function
SYNTAX:-
transalte(string char which u want replace with )
Suppose for the EMPLOYEE table....
SQL>SELECT TRASLATE
(upper(ENAME)
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'EFGHIJKLMNOPQRSTUVWXYZABCD')
FROM EMP
-- THIS CHARCTER REPLACED BY --
A REPLACED BY E
B '' F
C " G
| |
| |
| |
/ /

Z D

every character that is present in the employee names in the emplooyee table
suppose name is
PAULL --------->TEYPP
LIKE this every chat is replaced by its corresponding character
We use traslate function inthe encryption of the data ...

 
Is this answer useful? Yes | No
April 07, 2009 11:17:07   #9  
ravindra1001 Member Since: December 2007   Contribution: 3    

RE: What is the Difference between Replace and Translate
replace function replaces a sequence of characters in a string with another set of characters.
ex.

select replace('123data' 123 'X') from dual;


REPLA
-----
Xdata

here 123 replaces by X

translate function replaces a sequence of characters in a string with another set of characters. However it replaces a single character at a time.
ex1.
select translate('1data23base' 123 'XYZ') from dual

TRANSLATE('
-----------
XdataYZbase

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape