PLSQL | TRANSLATE Function
The PLSQL TRANSLATE function is used for replacing a sequence of characters in a string with another set of characters. The PLSQL TRANSLATE function replaces a single character at a time. The TRANSLATE function replaces the first character of the input_string with the first character of the replacement_string and then the second character and follows the same flow for the remaining characters.
The TRANSLATE function accepts three parameters input_string, string_to_replace, replacement_string. If a character appears multiple times in string_to_replace, then the replacement_string mapping corresponding to the first occurrence is used. The TRANSLATE function returns a string value.
Syntax:
TRANSLATE( input_string, string_to_replace, replacement_string )
Parameters Used:
- input_string – It is used to specify the source string.
- string_to_replace – It is used to specify the string that will be searched for in the input_string.
- replacement_string – It is used to specify the characters which will be replaced with the corresponding character in the input_string.
Return Value:
The TRANSLATE function in PLSQL returns a string value.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Example-1: Passing all the three parameters to the TRANSLATE function to replace consecutive letters from the input_string.
DECLARE Test_String string(25) := 'Giiksforgiiks'; BEGIN dbms_output.put_line(TRANSLATE(Test_String, 'ii', 'ee')); END;
Output:
Geeksforgeeks
Example-2: Passing all the three parameters to the TRANSLATE function to replace non-consecutive letters from the input_string.
DECLARE Test_String string(25) := 'Geeksforgeeks'; BEGIN dbms_output.put_line(TRANSLATE(Test_String, 'Gkrs', 'abcd')); END;
Output:
aeebdfocgeebd
Example-3: Passing all the three parameters to the TRANSLATE function to replace uppercase and lowercase letters from the input_string.
DECLARE Test_String string(25) := 'Geeksforgeeks'; BEGIN dbms_output.put_line(TRANSLATE(Test_String, 'Gg', 'Aa')); END;
Output:
Aeeksforaeeks
Advantage:
- REPLACE can be used to substitute a single string for another single string, as well as remove character strings.
- TRANSLATE can be used to make several single-character, one-to-one substitutions in one operation.
Recommended Posts:
- PLSQL | COS Function
- PLSQL | ABS Function
- PLSQL | CHR Function
- PLSQL | LOG Function
- PLSQL | SIN Function
- PLSQL | MOD Function
- PLSQL | TAN Function
- PLSQL | LEAST Function
- PLSQL | LN Function
- PLSQL | EXP Function
- PLSQL | ASCII Function
- PLSQL | COSH Function
- PLSQL | LENGTHC Function
- PLSQL | INSTR2 Function
- PLSQL | EXTRACT Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



