BASE64_ENCODE v17
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 to translate to Base64.
loid
loid
specifies the object ID of a large object to translate to Base64.
Examples
Before executing the example, invoke the command:
SET bytea_output = escape;
This command instructs the server to escape any nonprintable characters and to display BYTEA
or RAW
values onscreen in readable form. For more information, see the Postgres core documentation.
This example first encodes a string that contains the text abc
using BASE64_ENCODE
and then decodes the string using BASE64_DECODE
:
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)
- On this page
- Parameters
- Examples