×

MySQL FROM_BASE64() function

In this context, we will learn how we can use the MySQL FROM_BASE64()() function with proper syntax and good examples.

Introduction of MySQL FROM_BASE64()() function

Basically, the FROM_BASE64() function In MySQL decodes a base-64 encoded string which gives us the result. More specifically, it takes a string encoded with the base-64 encoding rules used by TO_BASE64(), and the decoded result as a binary string is returned by it.

Syntax of the MySQL FROM_BASE64()() function

The syntax of the MySQL FROM_BASE64()() function is given as follows

FROM_BASE64(str);

Parameters or arguments used in MySQL FROM_BASE64()() function:

There is only one parameter accepted by the FROM_BASE64()() function in MySQL, which are given as follows:

Str- it is the base-64 encoded string that we want to decode.

Returns:

It will return the decoded result as a binary string.

Application used for FROM_BASE64()() function:

The FROM_BASE64()() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL FROM_BASE64()() function:

Now we will look into some MySQL FROM_BASE64()() function examples and will explore how we can use the FROM_BASE64() function in MySQL.

Example 1 – Basic Usage of MYSQL from_base() FUNCTION

Here's an example for a demonstration of the basic usage:

SELECT FROM_BASE64('Q2F0');

Output:

Cat
1 row in set (0.00 sec)

In this SELECT query, our argument is Q2F0, which is the base-64 encoded string for Cat.

Now, we are going to find the base-64 encoded string by passing Cat to the TO_BASE64() function:

SELECT TO_BASE64('Cat');

Output:

Q2F0
1 row in set (0.00 sec)

Example 2 – Example of a Longer String

Here's an example which uses a longer string:

SELECT FROM_BASE64('TXkgY2F0IGxpa2VzIHRvIGNoYXNlIGVsZXBoYW50cyE=');

Output:

My Cat likes to chase elephants!
1 row in set (0.00 sec)

Example 3 – Invalid Argument

If the argument is not a valid base-64 string, NULL will be returned:

SELECT FROM_BASE64('Oops!');

Output:

NULL
1 row in set (0.00 sec)

Example 4 – NULL Argument

We will also get NULL if we pass NULL string as an argument:

SELECT FROM_BASE64(NULL);

Output:

FROM_BASE64(NULL)
NULL
1 row in set (0.00 sec)

Example 5 – Missing Argument

We will get an error if we don't pass argument in the function:

SELECT FROM_BASE64();

Output:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'FROM_BASE64.'

Example 6 – Too Many Arguments

We'll also get an error if we pass too many arguments:

SELECT FROM_BASE64('Q2F0', 'RWxlcGhhbnQ=');

Output:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'FROM_BASE64.'

Application of MySQL FROM_BASE64()() function:

This function is used to decode a base-64 encoded string in MySQL.

Summary:

In the above context, we have learned how we can use the FROM_BASE64()() function in MySQL used to take a string encoded with the base-64 encoding rules used by TO_BASE64() and will return the decoded result as a binary string.


Related Topics

MySQL SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.

MySQL Table

Introduction MySQL table is an essential part of the system. MySQL table stores data using index, rows, and columns. It accesses data from the server quickly because of the table—this table...

22 minutes read.

MySQL ISNULL function

This function is used to check the null value in table data. It returns the result in a Boolean form. If table data is null, then the output becomes 1....

2 minutes read.

MySQL Character Length Function

In this context, we will learn how we can use the MySQL CHARACTER_LENGTH() function with proper syntax and good examples. Introduction of MySQL CHARACTER_LENGTH() function CHARACTER_LENGTH() function in MySQL is used to...

2 minutes read.

MySQL DATEDIFF() function

In this context, we will learn how we can use the MySQL DATEDIFF() function with proper syntax and good examples. Introduction of MySQL DATEDIFF() function DATEDIFF() function in MySQL is used to...

3 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 minutes read.

MySQL REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 minutes read.

MySQL Drop Index

Sometimes we have an index that is not required in data operations. In that case, we can use this statement to remove an existing index from the table. We can...

4 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic...

6 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL vs SQL

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL Environmental Setup

The MySQL Environmental Setup MySQL is free, open-source, and cross-platform software, which can be downloaded from its official website. MySQL management system installs on Linux, macOS, and windows. MySQL requires a framework...

6 minutes read.

MySQL ASIN() Function

In this context we will learn how we can use the ASIN() function in MySQL with proper syntax and good example. Introduction of MySQL ASIN() function The arc sine value of a...

2 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL QUARTER() function

In this context, we will learn how we can use the MySQL QUARTER() function with proper syntax and good examples. Introduction of MySQL QUARTER() function The QUARTER() function in MySQL returns the...

3 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL View

Introduction MySQL View is a virtual table to create a clone of the base table. The View does not contain its values or data. MySQL View creates to connect more than...

12 minutes read.