The UTL_RAW.TRANSLATE procedure performs a byte-by-byte translation on data of the RAW data type.
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 | A set of bytes to be found and replaced. |
| to_set | The target byte set. |
Considerations
Scans the value of the source byte string r in bytes:
- If this value is present in
from_set, the corresponding byte into_setis used. - If the byte is not found in
from_set, it is directly copied to the result. - A byte in
from_setis deleted if it does not have a corresponding item into_set. If thefrom_setstring is longer than theto_setstring and some bytes in thefrom_setstring do not have corresponding translations, the matching bytes are deleted. - If
to_setis longer thanfrom_set, the extra bytes into_setare ignored. - If a byte is repeated in
from_set, the duplicate bytes are ignored. - An exception is raised if any of the three parameters are
NULLor have a length of0. - If the length of the BYTES value is odd, a
0is added to the left during processing.
Use case
Execute the following statement by using the UTL_RAW.TRANSLATE function to replace the specified character in the input byte sequence with F, and preserve the rest of the characters.
obclient> SELECT UTL_RAW.TRANSLATE('1236567812125612344434341234567890ABAA1234','12AA34','FFFFFF') FROM dual;
The query returns the result as follows:
+-----------------------------------------------------------------------------------+
| UTL_RAW.TRANSLATE('1236567812125612344434341234567890ABAA1234','12AA34','FFFFFF') |
+-----------------------------------------------------------------------------------+
| FF365678FFFF56FFFF44FFFFFFFF567890ABFFFFFF |
+-----------------------------------------------------------------------------------+