Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Decoding base64-encoded string through FROM_BASE64 () function in MySQL

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I don't know if you have any knowledge about the similar articles in MySQL that use the FROM_BASE64 () function to decode base64-encoded strings. Today, I'm here to give you a brief introduction. If you are interested, let's take a look at the body. I believe you will get something after reading the FROM_BASE64 () function to decode the base64-encoded string in MySQL.

In MySQL, the FROM_BASE64 () function decodes a base-64-encoded string and returns the result. More specifically, it accepts a string encoded with the base-64 encoding rules used by TO_BASE64 () and returns the decoded result in the form of a binary string.

The syntax of FROM_BASE64 () is as follows:

FROM_BASE64 (str)

Where the parameter str is the base-64-encoded string you want to decode.

Example 1-basic usage

Here is an example to demonstrate the basic usage:

SELECT FROM_BASE64 ('Q2F0')

Results:

+-+ | FROM_BASE64 ('Q2F0') | +-+ | Cat | +-+

In this example, our parameter is Q2F0, which is the base-64-encoded string of Cat.

We can get the base-64-encoded string by passing Cat to the TO_BASE64 () function:

SELECT TO_BASE64 ('Cat')

Results:

+-+ | TO_BASE64 ('Cat') | +-+ | Q2F0 | +-+

Example 2-A long string

Here is an example of using a longer string:

SELECT FROM_BASE64 ('TXkgY2F0IGxpa2VzIHRvIGNoYXNlIGVsZXBoYW50cyE=')

Results:

+-+ | FROM_BASE64 ('TXkgY2F0IGxpa2VzIHRvIGNoYXNlIGVsZXBoYW50cyE=') | + -+ | My cat likes to chase elephants! | +-- +

Example 3-invalid parameter

If the parameter is not a valid base-64 string, NULL is returned:

SELECT FROM_BASE64 ('Oopsfolk')

Results:

+-- + | FROM_BASE64 ('Oopsfolk') | +-- + | NULL | +-- +

Example 4-NULL parameters

If you pass in NULL, you will also get NULL:

SELECT FROM_BASE64 (NULL)

Results:

+-+ | FROM_BASE64 (NULL) | +-+ | NULL | +-+

Example 5-missing parameter

If you don't pass a parameter, you'll get an error:

SELECT FROM_BASE64 ()

Results:

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

Example 6-too many parameters

If you pass in too many parameters, you will also get an error:

SELECT FROM_BASE64 ('Q2F0,' RWxlcGhhbnQ=')

Results:

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

After reading the article in MySQL that decodes base64-encoded strings through the FROM_BASE64 () function, what do you think? If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report