2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Difference between replace and translate

What is the difference between replace and translate, in that which is having better performance
userimage

Both functions looks similar but there are some subtle difference. We can say Translate is an extended version of Replace.

 

REPLACE

TRANSLATE

Replaces entire string at a time

Replaces character one-to-one basis

Returns string if no match found

Returns null if no match found

 

Syntax: TRANSLATE(string, from_string, to_string)

Example 1:-

SQL> select translate(‘sqlandplsql’, ‘sql’, ‘sequel’) as str from dual;

STR
———–
seqandpqseq

 

Syntax:- REPLACE(‘input string’,’find_string’,’replace_string’);

Example:-

1. Below query replaced ‘sql’ with ‘sequel’

SQL>  select replace(‘sqlandplsql’,’sql’,’sequel’) as replace_string from dual;

REPLACE_STRING
—————–
sequelandplsequel


Answer is