The MySQL DECODE() function is used for decoding an encoded string and return the original string. The MySQL DECODE() function returns empty strings if the encoded string is an empty string.
The DECODE() function accepts two parameters which are the encoded string to be decoded and the password string to decode the encoded string.
Syntax:
DECODE(encoded_string, password_string);Parameters Used:
- encoded_string - It is used to specify the encoded string that is to be decoded.
- password_string - It is used to specify the password string to decode the encoded string.
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
SELECT
DECODE(ENCODE('geeksforgeeks', 'passwordstring'), 'passwordstring');
Output:
geeksforgeeksExample-2: Implementing DECODE function on a string which has a combination of characters and integers.
SELECT
DECODE(ENCODE('geeksforgeeks123', 'passwordstring'), 'passwordstring');
Output:
geeksforgeeks123Example-3: Implementing DECODE function on a NULL string and returning the length of the string after compression.
SELECT
DECODE(ENCODE('NULL', 'passwordstring'), 'passwordstring');
Output:
NULL