TRANSLATE function in Oracle SQL with example

The TRANSLATE function in Oracle SQL is used to replace a set of characters in a string with another set of characters. 

TRANSLATE function in Oracle SQL with example

It takes three arguments:

  1. The input string
  2. The set of characters to be replaced
  3. The set of replacement characters

Here is an example of how to use the TRANSLATE function in Oracle SQL


SELECT TRANSLATE('HELLO WORLD', 'OD', 'XY') AS TRANSLATED_STRING

FROM DUAL;


YOU MAY ALSO LOOK: - SQL cheat sheet for interview pdf


In this example, the input string is 'HELLO WORLD', and we want to replace all occurrences of the characters 'O' and 'D' with the characters 'X' and 'Y', respectively. The FROM DUAL clause is used to ensure that the query returns a single row, as required by the SELECT statement.

The result of this query would be:


OUTPUT:-

TRANSLATE function in Oracle SQL with example





Post a Comment

Previous Post Next Post