Table of Contents
This chapter briefly introduces the UTL_ENCODE package, and describes how to use the functions of the package.
UTL_ENCODE provides functions that encode RAW data into a standard encoded format so that the data can be transmitted between hosts.
This section describes the functions provided by the UTL_ENCODE package, in alphabetical order.
Converts a BASE64-encoded RAW string to the original binary value.
Details about the BASE64_DECODE function are as follows:
Prototype
FUNCTION BASE64_DECODE ( r IN RAW ) RETURN RAW;
Parameter
Parameter | Description |
---|---|
r | Encoded RAW string. |
Example
DECLARE org raw(100); enc raw(100); BEGIN org := 'aaabae64ecde'; enc := UTL_ENCODE.BASE64_ENCODE(org); ... org := UTL_ENCODE.BASE64_DECODE(enc); ... END; /
Converts the RAW binary value to a BASE64-encoded RAW string.
Details about the BASE64_ENCODE function are as follows:
Prototype
FUNCTION BASE64_ENCODE ( r IN RAW ) RETURN RAW;
Parameter
Parameter | Description |
---|---|
r | RAW string to encode. |
Example
DECLARE org raw(100); enc raw(100); BEGIN org := 'aaabae64ecde'; enc := UTL_ENCODE.BASE64_ENCODE(org); ... END; /
Decodes a string that is encoded to a quoted-printable format.
Details about the QUOTED_PRINTABLE_DECODE function are as follows:
Prototype
FUNCTION QUOTED_PRINTABLE_DECODE ( r IN RAW ) RETURN RAW;
Parameter
Parameter | Description |
---|---|
r | RAW string to decode. |
Return Value
Return Value | Description |
---|---|
RAW | Decoded RAW string. |
Example
DECLARE
src VARCHAR2(32767);
tar RAW(32767);
dec RAW(32767);
BEGIN
src := 'tib=ero';
tar := UTL_ENCODE.QUOTED_PRINTABLE_ENCODE(UTL_RAW.CAST_TO_RAW(src));
dec := UTL_ENCODE.QUOTED_PRINTABLE_DECODE(tar);
DBMS_OUTPUT.PUT_LINE('ENCODED DATA :' || UTL_RAW.CAST_TO_VARCHAR2(tar));
DBMS_OUTPUT.PUT_LINE('DECODED DATA :' || UTL_RAW.CAST_TO_VARCHAR2(dec));
END;
/
Encodes a RAW string to a quoted-printable format.
Details about the QUOTED_PRINTABLE_ENCODE function are as follows:
Prototype
FUNCTION QUOTED_PRINTABLE_ENCODE ( r IN RAW ) RETURN RAW;
Parameter
Parameter | Description |
---|---|
r | RAW string to encode. |
Return Value
Return Value | Description |
---|---|
RAW | Encoded RAW string. |
Example
DECLARE
src VARCHAR2(32767);
tar RAW(32767);
dec RAW(32767);
BEGIN
src := 'tib=ero';
tar := UTL_ENCODE.QUOTED_PRINTABLE_ENCODE(UTL_RAW.CAST_TO_RAW(src));
dec := UTL_ENCODE.QUOTED_PRINTABLE_DECODE(tar);
DBMS_OUTPUT.PUT_LINE('ENCODED DATA :' || UTL_RAW.CAST_TO_VARCHAR2(tar));
DBMS_OUTPUT.PUT_LINE('DECODED DATA :' || UTL_RAW.CAST_TO_VARCHAR2(dec));
END;
/
Decodes a string to a specified character set. After decoding, the input text is converted according to its character set.
Details about the TEXT_DECODE function are as follows:
Prototype
FUNCTION TEXT_DECODE ( buf IN VARCHAR2, encode_charset IN VARCHAR2 DEFAULT NULL, encoding IN PLS_INTEGER DEFAULT NULL ) RETURN VARCHAR2;
Parameter
Parameter | Description |
---|---|
buf | Text string to decode. |
encode_charset | Source character set. If NULL, the character set is not changed. (Default value: NULL) The text string is converted from this character set to the database character set. |
encoding | Encoding format.
If set to NULL, decodes from quoted-printable. |
Example
DECLARE
src VARCHAR2(32767);
tar VARCHAR2(32767);
dec VARCHAR2(32767);
BEGIN
src := 'tibero';
tar := UTL_ENCODE.TEXT_ENCODE(src, NULL, UTL_ENCODE.BASE64);
dec := UTL_ENCODE.TEXT_DECODE(tar, NULL, UTL_ENCODE.BASE64);
DBMS_OUTPUT.PUT_LINE('ENCODED DATA :' || tar);
DBMS_OUTPUT.PUT_LINE('DECODED DATA :' || dec);
END;
/
Encodes a text string to a specified character set. After encoding, the input text is converted according to its character set.
Details about the TEXT_ENCODE function are as follows:
Prototype
FUNCTION TEXT_ENCODE ( buf IN VARCHAR2, encode_charset IN VARCHAR2 DEFAULT NULL, encoding IN PLS_INTEGER DEFAULT NULL ) RETURN VARCHAR2;
Parameter
Parameter | Description |
---|---|
buf | Text string to encode. |
encode_charset | Target character set. Since character set conversion is currently not supported, use the default value. (Default value: NULL) |
encoding | Encoding format.
If set to NULL, decodes from quoted-printable. |
Example
DECLARE
src VARCHAR2(32767);
tar VARCHAR2(32767);
BEGIN
src := 'tibero';
tar := UTL_ENCODE.TEXT_ENCODE(src, NULL, 1);
...
END;
/