The built-in UTL_ENCODE package provides a set of functions for data encoding and decoding that facilitate data transmission between hosts.
Overview
Function | Description |
BASE64_DECODE Function | Reads Base64-encoded RAW data and decodes it into RAW data. |
BASE64_ENCODE Function | Reads RAW data, encodes it into Base64 data, and returns corresponding RAW data. |
MIMEHEADER_DECODE Function | Decodes a VARCHAR2 string in the MIMEHEADER format. |
MIMEHEADER_ENCODE Function | Encodes a string into the MIMEHEADER format. |
QUOTED_PRINTABLE_DECODE Function | Reads RAW data in the QUOTED_PRINTABLE format and decodes it into corresponding RAW data. |
QUOTED_PRINTABLE_ENCODE Function | Reads RAW data in the QUOTED_PRINTABLE format and encodes it into corresponding RAW data. |
TEXT_DECODE Function | Decodes a string based on the character set and decoding mode. |
TEXT_ENCODE Function | Encodes a string based on the character set and encoding method. |
UUDECODE Function | Reads RAW data in the UUENCODE format and decodes it to corresponding RAW data. |
UUENCODE Function | Reads RAW data and encodes it into RAW data in the UUENCODE format. |
BASE64_DECODE
This function reads Base64-encoded RAW data and decodes it into RAW data.
Syntax
UTL_ENCODE.BASE64_DECODE (
r IN RAW)
RETURN RAW;Parameters
Parameter | Description |
r | Base64-encoded RAW data. |
Return values
Return value | Description |
RAW | The decoded RAW data. |
Example
This example shows how to decode Base64-encoded data into RAW data.
select utl_encode.base64_decode(utl_encode.base64_encode('base64encoding'::raw));
base64_decode
----------------------------
\x626173653634656e636f64696e67
(1 row)BASE64_ENCODE
This function reads RAW data, encodes it into a sequence of BASE64 symbols, and returns the corresponding RAW data.
Syntax
UTL_ENCODE.BASE64_ENCODE (
r IN RAW)
RETURN RAW;Parameters
Parameter | Description |
r | The RAW data to be encoded. |
Return values
Return value | Description |
RAW | The encoded RAW data. |
Example
This example shows how to encode data into RAW data in the BASE64 format.
select utl_encode.base64_encode('base64encoding'::raw);
base64_encode
------------------------------------
\x596d467a5a5459305a57356a62325270626d633d
(1 row)MIMEHEADER_DECODE
This function decodes a string in the MIMEHEADER format into a raw string.
Syntax
UTL_ENCODE.MIMEHEADER_DECODE (
buf IN VARCHAR2)
RETURN VARCHAR2;Parameters
Parameter | Description |
buf | The string in the MIMEHEADER format to be decoded. |
Return values
Return value | Description |
VARCHAR2 | The decoded string. |
Example
This example shows how to decode data in the MIMEHEADER format.
select utl_encode.mimeheader_decode('=?UTF8?Q?mimeheaderencoding?=');
mimeheader_decode
--------------------
mimeheaderencoding
(1 row)MIMEHEADER_ENCODE
This function encodes a string into a string in the MIMEHEADER format.
Syntax
UTL_ENCODE.MIMEHEADER_ENCODE (
buf IN VARCHAR2,
encode_charset IN VARCHAR2 DEFAULT NULL,
encoding IN INTEGER DEFAULT NULL)
RETURN VARCHAR2;Parameters
Parameter | Description |
buf | The data to be encoded. |
encode_charset | The target character set. |
encoding | The encoding format. Valid values:
|
Return values
Return value | Description |
VARCHAR2 | The decoded string. |
Example
This example shows how to encode a string into data in the MIMEHEADER format.
select utl_encode.mimeheader_encode('mimeheaderencoding');
mimeheader_encode
-------------------------------
=?UTF8?Q?mimeheaderencoding?=
(1 row)QUOTED_PRINTABLE_DECODE
This function reads RAW data in the QUOTED_PRINTABLE format and decodes it into corresponding RAW data.
Syntax
UTL_ENCODE.QUOTED_PRINTABLE_DECODE (
r IN RAW)
RETURN RAW;Parameters
Parameter | Description |
r | The RAW data in the QUOTED_PRINTABLE format. |
Return values
Return value | Description |
RAW | The decoded RAW data. |
Example
This example shows how to decode data in the QUOTED_PRINTABLE format into corresponding RAW data.
select utl_encode.quoted_printable_decode(utl_encode.quoted_printable_encode('quoted_printable'::raw));
quoted_printable_decode
------------------------------------
\x71756f7465645f7072696e7461626c65
(1 row)QUOTED_PRINTABLE_ENCODE
This function reads RAW data and encodes it into corresponding RAW data in the QUOTED_PRINTABLE format.
Syntax
UTL_ENCODE.QUOTED_PRINTABLE_ENCODE (
r IN RAW)
RETURN RAW;Parameters
Parameter | Description |
r | The input RAW data. |
Return values
Return value | Description |
RAW | The encoded RAW data. |
Example
This example shows how to encode data into RAW data in the QUOTED_PRINTABLE format.
select utl_encode.quoted_printable_encode('quoted_printable'::raw);
quoted_printable_encode
------------------------------------
\x71756f7465645f7072696e7461626c65
(1 row)TEXT_DECODE
This function decodes data by using the specified encoding mode and character set.
Syntax
UTL_ENCODE.TEXT_DECODE(
buf IN VARCHAR2,
encode_charset IN VARCHAR2 DEFAULT NULL,
encoding IN PLS_INTEGER DEFAULT NULL)
RETURN VARCHAR2;Parameters
Parameter | Description |
buf | The data to be decoded. |
encode_charset | The target character set. |
encoding | The encoding format of the data. Valid values:
|
Return values
Return value | Description |
VARCHAR2 | The decoded string. |
Example
This example shows how to decode the data obtained by the corresponding encoding function.
select utl_encode.text_decode('text encoding test=3D');
text_decode
---------------------
text encoding test=
(1 row)TEXT_ENCODE
This function encodes data into output of the corresponding character set.
Syntax
UTL_ENCODE.TEXT_ENCODE (
buf IN VARCHAR2,
encode_charset IN VARCHAR2 DEFAULT NULL,
encoding IN INTEGER DEFAULT NULL)
RETURN VARCHAR2;Parameters
Parameter | Description |
buf | The data to be encoded. |
encode_charset | The target character set. |
encoding | The encoding format of the data. Valid values:
|
Return values
Return value | Description |
VARCHAR2 | The encoded data. |
Example
The example shows how to convert data to a specified character set and encode it.
select utl_encode.text_encode('text encoding test=');
text_encode
-----------------------
text encoding test=3D
(1 row)UUDECODE
This function reads UUENCODE-encoded RAW data and decodes it into corresponding RAW data.
Syntax
UTL_ENCODE.UUDECODE (
r IN RAW)
RETURN RAW;Parameters
Parameter | Description |
r | RAW data in the UUENCODE format. |
Return values
Return value | Description |
RAW | The decoded RAW data. |
Example
This example shows how to decode UUENCODE-encoded data.
select utl_encode.uudecode(utl_encode.uuencode('uuencode test'));
uudecode
------------------------------
\x7575656e636f64652074657374
(1 row)UUENCODE
This function encodes RAW data into RAW data in the UUENCODE format.
Syntax
UTL_ENCODE.UUENCODE (
r IN RAW,
type IN INTEGER DEFAULT 1,
filename IN VARCHAR2 DEFAULT NULL,
permission IN VARCHAR2 DEFAULT NULL) RETURN RAW;Parameters
Parameter | Description |
r | The input RAW data. |
type | (Optional) the UUENCODE output format. This parameter is of the numeric type. Default value: 1, which indicates the complete output format. |
filename | (Optional) the UUENCODE file name. Default value: |
permission | (Optional) the permission information. This parameter is of the VARCHAR2 type. Default value: |
Return values
Return value | Description |
RAW | The input RAW data. |
Example
This example shows how to encode data into the UUENCODE format.
select utl_encode.uuencode('uuencode test');
uuencode
------------------------------------------------------------------------------------------------------
\x626567696e2030207575656e636f64652e7478740d0a323d3735453b462d4f392634403d2635533d2020200d0a0a656e64
(1 row)