The UTL_RAW.TRANSLATE function is a byte-level translation function that converts RAW data byte by byte.
Syntax
UTL_RAW.TRANSLATE (
r IN RAW,
from_set IN RAW,
to_set IN RAW
) RETURN RAW;
Parameters
| Parameter | Description |
|---|---|
| r | The source byte string. |
| from_set | The set of bytes to find and replace. |
| to_set | The set of bytes to replace with. |
Considerations
The function scans the source byte string r byte by byte:
- If the value is found in
from_set, it is replaced with the corresponding byte into_set. - If the byte is not found in
from_set, it is copied to the result. - If a byte in
from_setdoes not have a corresponding byte into_set, it is deleted. - If
from_setis longer thanto_set, any extra bytes infrom_setwithout a corresponding translation are deleted. - If
to_setis longer thanfrom_set, any extra bytes into_setare ignored. - If a byte appears multiple times in
from_set, only the first occurrence is considered. - If any of the three parameters is
NULLor has a length of0, aValueErroris raised. - If the byte string length is odd, a
0is added to the left side during processing.
Examples
Execute the following command to use the UTL_RAW.TRANSLATE function to replace all instances of a specific character in the input byte sequence with F, while leaving other characters unchanged.
obclient> SELECT UTL_RAW.TRANSLATE('1236567812125612344434341234567890ABAA1234','12AA34','FFFFFF') FROM dual;
The result is as follows:
+-----------------------------------------------------------------------------------+
| UTL_RAW.TRANSLATE('1236567812125612344434341234567890ABAA1234','12AA34','FFFFFF') |
+-----------------------------------------------------------------------------------+
| FF365678FFFF56FFFF44FFFFFFFF567890ABFFFFFF |
+-----------------------------------------------------------------------------------+
