UTL_RAW.TRANSLATE 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 byte set to be found and replaced. |
| to_set | The target byte set for replacement. |
Considerations
The source byte string r is scanned 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 directly copied to the result. - If the byte in
from_sethas no corresponding item into_set, the byte is deleted. - If
from_setis longer thanto_set, the extra bytes infrom_setthat have no corresponding translation are deleted. - If
to_setis longer thanfrom_set, the extra bytes into_setare ignored. - If there are duplicate bytes in
from_set, the duplicates are ignored (the corresponding relationships of the duplicate bytes are ignored). - If any of the three parameters is
NULLor has a length of0, aValueErroris returned. - If the length of the byte string is odd, a
0is added to the left side of the byte string during processing.
Examples
Execute the following command to use the UTL_RAW.TRANSLATE function to replace specific characters in the input byte sequence with F and retain the 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 |
+-----------------------------------------------------------------------------------+