Oracle UTL_ENCODE
Version 21c

General Information
Library Note Morgan's Library Page Header
ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling complimentary technical Workshops on Database Security for the first 30 Oracle Database customers located anywhere in North America, EMEA, LATAM, or APAC that send an email to asra_us@oracle.com. Request a Workshop for your organization today.
Purpose This package contains BASE64, Mime, Text, and UU encode and decode RAW data string functions that encode data into a standard encoded format so that the data can be transported between hosts. This package's objects can be used to encode the body of email text. The package also contains the decode counterpart functions of the encode functions. The functions follow published standards for encoding to accommodate non-Oracle utilities on the sending or receiving ends.
AUTHID DEFINER
Constants
Name Data Type Value
base64 PLS_INTEGER 1
complete (header & footer) PLS_INTEGER 1
end_piece (includes footer text) PLS_INTEGER 4
header_piece (includes heaer text) PLS_INTEGER 2
middle_piece (body text only) PLS_INTEGER 3
quoted_printable PLS_INTEGER 2
Dependencies
DBMS_AW_EXP DBMS_ISCHED_REMOTE_ACCESS UTL_MAIL
DBMS_DEBUG UTL_ENC_LIB UTL_SMTP
DBMS_ISCHED    
Documented Yes
First Available 9.0.1
Security Model Owned by SYS with EXECUTE granted to PUBLIC
Source {ORACLE_HOME}/rdbms/admin/utlenc.sql
Subprograms
 
BASE64_DECODE
Reads the base 64-encoded RAW input string and decodes it to its original RAW value utl_encode.base64_decode(r IN RAW) RETURN RAW;
See base64_encode Demo Below
 
BASE64_ENCODE
Encodes the binary representation of the RAW value into base 64 elements and returns it in the form of a RAW string utl_encode.base64_encode(r IN RAW) RETURN RAW;
set serveroutput on

DECLARE
 r RAW(32767);
BEGIN
  r := utl_raw.cast_to_raw('University of Washington');
  dbms_output.put_line(r);

  r := utl_encode.base64_encode(r);
  dbms_output.put_line(r);

  r := utl_encode.base64_decode(r);
  dbms_output.put_line(r);
END;
/
 
MIMEHEADER_DECODE
Decodes a string from mime header format utl_encode.mimeheader_decode(buf IN VARCHAR2 CHARACTER SET ANY_CS)
RETURN data VARCHAR2 CHARACTER SET buf%CHARSET;
See mimeheader_encode Demo Below
 
MIMEHEADER_ENCODE
Encodes a string into mime header format utl_encode.mimeheader_encode(
buf            IN VARCHAR2 CHARACTER SET ANY_CS,
encode_charset IN VARCHAR2    DEFAULT NULL,
encoding       IN PLS_INTEGER DEFAULT NULL);
RETURN string VARCHAR2 CHARACTER SET buf%CHARSET;
set serveroutput on

DECLARE
 t VARCHAR2(100);
BEGIN
  t := utl_encode.mimeheader_encode('MLIB');
  dbms_output.put_line(t);

  t := utl_encode.mimeheader_decode(t);
  dbms_output.put_line(t);
END;
/
 
QUOTED_PRINTABLE_DECODE
Reads the varchar2 quoted printable format input string and decodes it to the corresponding RAW string utl_encode.quoted_printable_decode(r IN RAW)
RETURN RAW;
See quoted_printable_encode Demo Below
 
QUOTED_PRINTABLE_ENCODE
Reads the RAW input string and encodes it to the corresponding quoted printable format string utl_encode.quoted_printable_encode(r IN RAW)
RETURN RAW;
set serveroutput on

DECLARE
r RAW(32767);
BEGIN
  r := utl_raw.cast_to_raw('Begin' || chr(13) || 'End');
  dbms_output.put_line(r);

  r := utl_encode.quoted_printable_encode(r);
  dbms_output.put_line(r);

  r := utl_encode.quoted_printable_decode(r);
  dbms_output.put_line(r);
END;
/
 
TEXT_DECODE
Decodes a character set sensitive text string utl_encode.text_decode(
buf            IN VARCHAR2 CHARACTER SET ANY_CS,
encode_charset IN VARCHAR2    DEFAULT NULL,
encoding       IN PLS_INTEGER DEFAULT NULL)
RETURN string VARCHAR2 CHARACTER SET buf%CHARSET;
See text_encode Demo Below
 
TEXT_ENCODE
Encodes a character set sensitive text string utl_encode.text_encode(
buf            IN VARCHAR2 CHARACTER SET ANY_CS,
encode_charset IN VARCHAR2    DEFAULT NULL,
encoding       IN PLS_INTEGER DEFAULT NULL)
RETURN string VARCHAR2 CHARACTER SET buf%CHARSET;
set serveroutput on

DECLARE
 c VARCHAR2(100);
BEGIN
  c := utl_encode.text_encode('Here is some text', 'WE8ISO8859P1', UTL_ENCODE.BASE64);

  dbms_output.put_line(c);
END;
/

DECLARE
 c VARCHAR2(100);
BEGIN
  c := utl_encode.text_decode('SGVyZSBpcyBzb21lIHRleHQ=',
  'WE8ISO8859P1', UTL_ENCODE.BASE64);

  dbms_output.put_line(c);
END;
/
 
UUDECODE
Reads the RAW uuencode format input string and decodes it to the corresponding RAW string utl_encode.uudecode(r IN RAW) RETURN RAW;
See uuencode Demo Below
 
UUENCODE
Reads the RAW input string and encodes it to the corresponding uuencode format string utl_encode.uuencode(
r          IN RAW,
type       IN PLS_INTEGER DEFAULT 1,
filename   IN VARCHAR2 DEFAULT NULL,
permission IN VARCHAR2 DEFAULT NULL)
RETURN RAW;
set serveroutput on

DECLARE
 r RAW(32767);
BEGIN
  r := utl_encode.uuencode('ABCFED', 1, 'uuencode.txt', 0);
  dbms_output.put_line('Encoded: ' || r);

  r := utl_encode.uudecode(r);
  dbms_output.put_line('Decoded: ' || r);
END;
/

Related Topics
Built-in Functions
Built-in Packages
UTL_MAIL
UTL_RAW
UTL_SMTP
What's New In 21c
What's New In 23c

Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2023 Daniel A. Morgan All Rights Reserved
  DBSecWorx