What is the difference between "translate" and "replace"?

Questions by Beena   answers by Beena

Editorial / Best Answer

jayaprakash.raman  

  • Member Since Apr-2007 | Apr 24th, 2007


Please refer that here we are discussing about Sql Server only. There is no function named 'Translate' in Sql Server. 'Translate' function exists in Oracle for translating a single character to some other character.

Replace fucntion in Sql server is used to replace a string as well as character to another string or character. No need to have a seperate function like Transalate in Oracle:

Find below the examples to get the clear idea:

Ex 1: Sql Server replace function similar to Oracle Replace function

Declare @Str varchar(100)

set @Str='India is my country'

print @Str

print replace(@Str,'India','Pakistan')



Result

India is my country

Pakistan is my country


Ex 1: Sql Server replace function similar to Oracle Translate Replace function

Declare @Str varchar(100)

set @Str='Think You'

print @Str

print replace(@Str,'i','a')
Result

Think You

Thank You



Note: Please try to post Sql server questions only here. Ther is a seperate section available for Oracle. If we mix both, it will confuse the people who are specializing their skill in particular area. Thank you.

Showing Answers 1 - 5 of 5 Answers

Replace replace every instence of character with character sting by the given charator of string. this work for entire word and pattern,. Translate replace the one charecte  at a time.Translating the nth character match with the nth character with the replacemnt string .

  Was this answer useful?  Yes

aruna

  • Apr 3rd, 2006
 

Translate is a character wise function

where as replace is a string wise

Please refer that here we are discussing about Sql Server only. There is no function named 'Translate' in Sql Server. 'Translate' function exists in Oracle for translating a single character to some other character.

Replace fucntion in Sql server is used to replace a string as well as character to another string or character. No need to have a seperate function like Transalate in Oracle:

Find below the examples to get the clear idea:

Ex 1: Sql Server replace function similar to Oracle Replace function

Declare @Str varchar(100)

set @Str='India is my country'

print @Str

print replace(@Str,'India','Pakistan')



Result

India is my country

Pakistan is my country


Ex 1: Sql Server replace function similar to Oracle Translate Replace function

Declare @Str varchar(100)

set @Str='Think You'

print @Str

print replace(@Str,'i','a')
Result

Think You

Thank You



Note: Please try to post Sql server questions only here. Ther is a seperate section available for Oracle. If we mix both, it will confuse the people who are specializing their skill in particular area. Thank you.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions