×

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 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 ROUND() function

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

3 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 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 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...

2 minutes read.

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 minutes read.

MySQL GREATEST function

This statement displays the greatest values of the table. The GREATEST function returns a null value when the table contains a null value. The GREATEST function needs a minimum of...

2 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 Control flow function

The control flow function uses values or operands for logical operations. These functions can works on single and multiple conditions. The control flow function is based on the Boolean expression....

3 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL PI() function

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

2 minutes read.

MySQL DATE_FORMAT() function

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

3 minutes read.

MySQL POW() function

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

2 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 minutes read.

MySQL LOCATE() function

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

3 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 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.