Chapter 54. UTL_ENCODE

Table of Contents

54.1. Overview
54.2. Functions
54.2.1. BASE64_DECODE
54.2.2. BASE64_ENCODE
54.2.3. QUOTED_PRINTABLE_DECODE
54.2.4. QUOTED_PRINTABLE_ENCODE
54.2.5. TEXT_DECODE
54.2.6. TEXT_ENCODE

This chapter briefly introduces the UTL_ENCODE package, and describes how to use the functions of the package.

54.1. Overview

UTL_ENCODE provides functions that encode RAW data into a standard encoded format so that the data can be transmitted between hosts.

54.2. Functions

This section describes the functions provided by the UTL_ENCODE package, in alphabetical order.

54.2.1. BASE64_DECODE

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

    ParameterDescription
    rEncoded 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;
    /

54.2.2. BASE64_ENCODE

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

    ParameterDescription
    rRAW string to encode.
  • Example

    DECLARE 
        org raw(100);
        enc raw(100);
    BEGIN
        org := 'aaabae64ecde';
        enc := UTL_ENCODE.BASE64_ENCODE(org);
        ...
    END;
    /

54.2.3. QUOTED_PRINTABLE_DECODE

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

    ParameterDescription
    rRAW string to decode.
  • Return Value

    Return ValueDescription
    RAWDecoded 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;
    /

54.2.4. QUOTED_PRINTABLE_ENCODE

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

    ParameterDescription
    rRAW string to encode.
  • Return Value

    Return ValueDescription
    RAWEncoded 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;
    /

54.2.5. TEXT_DECODE

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

    ParameterDescription
    bufText 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.

    • 1: Decode from BASE64 format.

    • 2: Decode from quoted-printable 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;
    /

54.2.6. TEXT_ENCODE

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

    ParameterDescription
    bufText 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.

    • 1: Encode to BASE64 format.

    • 2: Encode to quoted-printable 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;
    /