×

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

Basically, the TAN() function in MySQL is used to give back the tangent of a mentioned number.In any kind of right-angle triangle, the tangent of an angle is the length...

2 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL MONTHNAME() function

In this context, we will learn how we can use the MySQL MONTHNAME() Function with proper syntax and good examples. Introduction of MySQL MONTHNAME() function In MySQL the MONTHNAME() Function 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 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 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 UPDATE JOIN

The UPDATE JOIN is a MySQL statement used to perform cross-table updates that means we can update one table using another table with the JOIN clause condition. The "update join"...

5 minutes read.

MySQL NOW() function

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

2 minutes read.

MySQL CEILING() function

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

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 Constraints

MySQL Constraints Introduction The constraints help to restrict what values should be stored in a table. The constraints provide limitations of the columns or data. This function helps to insert data in...

20 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 Advance function

The advance function operates numerical values, string values, and data types.  The advance function converts, displays, and compares given values as per requirement. Here, you find out database, table, and...

4 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 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 Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL LIKE() function

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

4 minutes read.