replace vs translate

  • Both replace and translate are string manipulating functions
  • Replace replaces the whole test
  • translate replaces character by chracter

Replace Example

select replace('Welcome to Oracle','Oracle','Java') as result from dual; --Welcome to Java

Translate Example

select translate('Welcome to Oracle','abcdefgh','12345678') as result from dual;--W5l3om5 to Or13l5

select translate('Welcome to Oracle','abcdef','123') as result from dual;--Wl3om to Or13l

--character 'd','e' and 'f' will be removed from string since it does not have a corresponding character to be replaced with

select translate ('ABC DEF GHI JKL MNO','ABCDEF','123') as result from dual;--123  GHI JKL MNO

select translate ('ABC DEF GHI JKL MNO','ABCDEF','') as result from dual;--null

Leave a Comment