| Oracle Translate & Replace Functions Version 26ai |
|---|
| General Information | ||
| Library Note |
|
|
| Purpose | TRANSLATE and REPLACE are very similar in their appearance but can produce very different results.
Translate replaces by position, the first character of the list to match is replaced by the first character of the replacement list.
The second character with the second, and if there are characters in the list to match that do not have positional equivalents in the replacements list they are dropped. Replace replaces the string to match with the replacement string. The replacement of a single character is the same as that of TRANSLATE. |
|
| TRANSLATE | ||
| Single character replacement that replaces all commas with vertical bars | TRANSLATE( |
|
SELECT translate ('comma,delimited,list', ',', '| ') |
||
| Multiple Character Replacement Turns a DNA sequence into its complement |
SELECT TRANSLATE('CAG-TTT-GAC-ACA-TGG-ATC', 'ACGT ', 'GATC') DNA; |
|
| Character Replacement and Elimination. The 'a' is replaced with an 'e', the 'h' has no complement and is dropped. | SELECT translate('So What', 'ah', 'e'); |
|
| Eliminating Double Quotes. Capital A is replaced with capital A. The double quote is eliminated because there is no match. | SELECT translate('"Darn double quotes "', 'A"', 'A'); |
|
| Simple encryption and decryption | SELECT translate('this is a secret', |
|
| Counting vowels | WITH data AS (SELECT 'Whose line is it anyway' line FROM dual) |
|
| REPLACE | ||
| VARCHAR2 demonstrating single character replacement Overload 1 |
-- REPLACE(<string>, <'string_to_match'>,<'replacements_string'>) |
|
conn uwclass/uwclass@pdbdev |
||
| CLOB demonstrating multiple character replacement Overload 2 |
REPLACE(<string>, <'string_to_match'>,<'replacements_string'>) |
|
conn uwclass/uwclass@pdbdev |
||
| Related Topics |
| Built-in Functions |
| REGEXP_REPLACE |
| String Functions |
| What's New In 21c |
| What's New In 26ai |
| This site is maintained by Daniel Morgan. Last Updated: | This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2026 Daniel A. Morgan All Rights Reserved | ||||||||
|
|
|||||||||