SQL base64 decoding
Decodes Base64 text back into the original bytes.
- Kategorie
- Strings
- Returns
binary string- In this category
- 132 of 172
Syntax
FROM_BASE64(string)
PostgreSQL: decode(value, 'base64')
Each block is a separate form. The support table and the examples show which engine takes which.
Engine-Unterstützung
| Engine | Support | Notizen |
|---|---|---|
| SQL Server | Different name or syntax | BASE64_DECODE(text) in SQL Server 2025 and Azure SQL; returns varbinary. |
| PostgreSQL | Different name or syntax | decode(str, 'base64') returns bytea; convert_from turns it into text. |
| MySQL | Ja | FROM_BASE64 is built in. |
| SQLite | Not built in | No Base64 built in. |
| Oracle | Different name or syntax | UTL_ENCODE.BASE64_DECODE on RAW values. |
Beispiele
MySQL
SELECT FROM_BASE64('aGVsbG8=') AS decoded; -- hello
PostgreSQL
SELECT convert_from(decode('aGVsbG8=', 'base64'), 'UTF8') AS decoded; -- hello
Gut zu wissen
- Invalid Base64 returns NULL in MySQL, so a NULL can mean corrupt input rather than missing data. PostgreSQL raises an error instead.
- The result is bytes: in MySQL CONVERT(FROM_BASE64(x) USING utf8mb4) for text; in PostgreSQL convert_from(decode(x, 'base64'), 'UTF8').
- Whitespace inside the input is skipped by MySQL (FROM_BASE64('aGVs bG8=') is 'hello') and by PostgreSQL, so MIME line breaks decode fine. Other stray characters still fail.
Questions about FROM_BASE64
Why does FROM_BASE64 return NULL for my string?
The input is not valid Base64: illegal characters (often the - and _ of base64url), bad padding, or a truncated value. Translate base64url back to + and / and restore padding first.
How do I get text back instead of bytes?
In PostgreSQL wrap the bytes: convert_from(decode(v, 'base64'), 'UTF8'). In MySQL convert the result: CONVERT(FROM_BASE64(v) USING utf8mb4).
Does FROM_BASE64 accept line breaks?
Yes. MySQL and PostgreSQL skip spaces, tabs and newlines, so 76-character MIME lines decode as one value.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.