Oracle UTL_ENCODE
Version 12.1.0.1

General Information
Library Note Morgan's Library Page Footer
The Library is currently in the process of being upgraded from Oracle Database Version 11.2.0.3 to 12.1.0.1. Demos are being upgraded to reflect the new Container paradigm as well as EBR (Edition Based Redefinition) and may contain references to CDBs, PDBs, and other objects you may not be familiar with such as CDB_OBJECTS_AE: Welcome to 12c.
Purpose BASE64, Mime, Text, and UU encode and decode RAW data strings
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 WWV_FLOW_MAIL WWV_FLOW_UTILITIES
UTL_ENC_LIB    
Documented No
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
Packages
UTL_MAIL
UTL_RAW
UTL_SMTP

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-2014 Daniel A. Morgan All Rights Reserved