BASE64_ENCODE v13

Use the BASE64_ENCODE function to translate and encode a string in Base64 format (as described in RFC 4648). This function can be useful when composing MIME email that you intend to send using the UTL_SMTP package. The BASE64_ENCODE function has two signatures:

BASE64_ENCODE(<r> IN RAW)

and

BASE64_ENCODE(<loid> IN OID)

This function returns a RAW value or an OID.

Parameters

r

r specifies the RAW string that will be translated to Base64.

loid

loid specifies the object ID of a large object that will be translated to Base64.

Examples

Before executing the following example, invoke the command:

SET bytea_output = escape;

This command instructs the server to escape any non-printable characters, and to display BYTEA or RAW values onscreen in readable form. For more information, refer to the Postgres Core Documentation available at:

https://www.postgresql.org/docs/current/static/datatype-binary.html

The following example first encodes (using BASE64_ENCODE), and then decodes (using BASE64_DECODE) a string that contains the text abc:

edb=# SELECT UTL_ENCODE.BASE64_ENCODE(CAST ('abc' AS RAW));
 base64_encode
---------------
 YWJj
(1 row)

edb=# SELECT UTL_ENCODE.BASE64_DECODE(CAST ('YWJj' AS RAW));
 base64_decode
---------------
 abc
(1 row)