w3resource

MySQL DECODE() function

DECODE() function

MySQL DECODE() function decodes an encoded string and returns the original string.

Syntax:

DECODE(crypt_str, pass_str);

Arguments:

Name Description
crypt_str An encoded string.
pass_str The password string to decode crypt_str.

Syntax Diagram:

MySQL decode() Function - Syntax Diagram

MySQL Version: 8.0


Example:

Code:

SELECT   DECODE(ENCODE('mytext','mykeystring'),'mykeystring');

Explanation:

The above MySQL statement decodes the encoded string 'mytext' as specified in the argument and returns the original string.

Output:

mysql> SELECT DECODE(ENCODE('mytext','mykeystring'),'mykeystring');
+------------------------------------------------------+
| DECODE(ENCODE('mytext','mykeystring'),'mykeystring') |
+------------------------------------------------------+
| mytext                                               | 
+------------------------------------------------------+
1 row in set (0.00 sec)

Example : MySQL decode() function using table

Sample table: testtable


Code:

SELECT description, DECODE(description,'mypassw')           
FROM testtable;

Explanation:

The above MySQL statement retrieves the decoded data from encoded 'description' column from 'testtable'.

Output:

mysql> SELECT description, DECODE(description,'mypassw')           
    -> FROM testtable;
+---------------------------+-------------------------------+
| description               | DECODE(description,'mypassw') |
+---------------------------+-------------------------------+
| ^5[@·˜,IÜç¦Éý          | zÝÀâ“x®,ÕCý’              | 
| Ô£^]Žþª_‹m              | myencodetext                  | 
| ÿ»(õ 2ñ«QèªöjD¸=ËTú9Ž! | ›zוämù…w¤xÿ&‚ÛjV|3üKÜ     | 
| ^5[@·˜,IÜç¦Éý          | zÝÀâ“x®,ÕCý’              | 
+---------------------------+-------------------------------+
4 rows in set (0.00 sec)

Previous: COMPRESS()
Next: DES_DECRYPT()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mysql/encryption-and-compression-functions/decode().php