×

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 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 INSERT() Function

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

2 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 HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

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 function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

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

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 Create index

An index creation helps to make a row of the table unique. The index operates and handles table data quickly. MySQL index requires NOT NULL column constraint. The index column...

2 minutes read.

MySQL INNER JOIN

MySQL inner join connects two tables by using their common columns. It is the basic join of the MySQL system. It is used to returns only those results from the...

4 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.

MySQL DAY() function

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

2 minutes read.

MySQL Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 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 RAND() function

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

3 minutes read.

MySQL LOAD_FILE() function

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

3 minutes read.

MySQL DATE_ADD() function

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

3 minutes read.

MySQL RIGHT() Function

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

3 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL RADIANS() function

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

2 minutes read.