Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of converting MySQL string to base64 Encoding

Shulou Source: shulou.com Published: 2022-06-01 18:44:06 10月05日 Update

This article mainly introduces the MySQL string to base64 coding methods, the contents of the article are carefully selected and edited by the author, with a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the MySQL string into base64 coding method.

Grammar

TO_BASE64 (str)

Where str is a string that needs to be encoded.

Example 1-basic usage

Here is an example to demonstrate the basic usage:

SELECT TO_BASE64 ('Dog')

Results:

+-+ | TO_BASE64 ('Dog') | +-+ | RG9n | +-+

In this example, the parameter is Dog, and once converted to base-64, it becomes RG9n.

We can use the FROM_BASE64 () function to decode the base-64 string:

SELECT FROM_BASE64 ('RG9n')

Results:

+-+ | FROM_BASE64 ('RG9n') | +-+ | Dog | +-+

Example 2-A long string

Here is an example of using a longer string:

SELECT TO_BASE64 ('My cat chases dogsgiving')

Results:

+-- + | TO_BASE64 ('My cat chases dogsgiving') | +-+ | TXkgY2F0IGNoYXNlcyBkb2dzIQ== | +-+

Example 3-non-string parameter

If the parameter is not a string, it is first converted to a string:

SELECT TO_BASE64 (123)

Results:

+-+ | TO_BASE64 (123) | +-+ | MTIz | +-

Example 4-NULL parameters

If you type NULL, you will get NULL:

SELECT TO_BASE64 (NULL)

Results:

+-+ | TO_BASE64 (NULL) | +-+ | NULL | +-+

Example 5-missing parameter

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

SELECT TO_BASE64 ()

Results:

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

Example 6-too many parameters

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

SELECT TO_BASE64 ('Cat',' Dog')

Results:

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

After reading the above methods of converting MySQL strings to base64 coding, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.

Tags: Characters strings parameters results codes methods examples authors industries errors information content functions meaning articles more friends columns knowledge grammar Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Xiaomi Microsoft NVidia