Using the TRANSLATE() Function: to encode and decode : Translate « Char Functions « Oracle PL / SQL






Using the TRANSLATE() Function: to encode and decode

SQL>
SQL> --Using the TRANSLATE() Function
SQL>
SQL> --TRANSLATE(x, from_string, to_string) to convert the occurrences of characters in from_string found in x to corresponding characters in to_string.
SQL>
SQL> --TRANSLATE(): shift each character in the string SECRET MESSAGE: MEET ME IN THE PARK by four places to the right: A becomes E, B becomes F
SQL>
SQL> SELECT TRANSLATE('SECRET MESSAGE: MEET ME IN THE PARK',
  2     'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  3     'EFGHIJKLMNOPQRSTUVWXYZABCD') FROM dual;

TRANSLATE('SECRETMESSAGE:MEETMEINTH
-----------------------------------
WIGVIX QIWWEKI: QIIX QI MR XLI TEVO

SQL>
SQL> --select translate('www.java2s.com','wjavscom','abced123') from dual;
SQL>
SQL>

           
       








Related examples in the same category

1.TRANSLATE() returns a string where all occurrences of the from_template are replaced with corresponding characters in the to_template.
2.from_template argument can contain more characters than to_template.
3.all dashes ("-") were dropped from the translated string, and the digit "9" was translated into an asterisk.
4.Translate: replaces a string character by character
5.TRANSLATE(x, from_string, to_string): Converts all occurrences of from_string in x to to_string
6.Shifts the lowercase as well as uppercase characters in a column
7.TRANSLATE(): convert numbers
8.Use translate function in update statement
9.TRANSLATE('555-143-3344', '1234567890','XXXXXXXXXX') phone