Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

MySQL | ENCODE( ) Function

  • Last Updated : 13 Nov, 2019

The MySQL ENCODE() function is used for encoding a plain text string. The MySQL ENCODE() function returns a binary string which of the same size of the plain text string. The MySQL DECODE() function returns empty strings if the string passed is an empty string.

The ENCODE() function accepts two parameters which are the string to be encoded and the key string to encode the plain text string.

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

Syntax:

ENCODE(plain_string, password_string);

Parameters Used:



  • plain_string – It is used to specify the plain text that is to be encoded.
  • password_string – It is used to specify the password string to encode the plain text string.

Return Value:
The ENCODE function in MySQL returns a binary string after encoding.

Supported Versions of MySQL:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1

Example-1: Implementing ENCODE function on a string.

SELECT  
ENCODE('geeksforgeeks', 'passwordstring'); 

Output:

Q)?P????j[K 

Example-2: Implementing ENCODE function on a string which has a combination of characters and integers.

SELECT  
ENCODE('geeksforgeeks123', 'passwordstring'); 

Output:

Q)?P????j[K??= 

Example-3: Implementing ENCODE function on a NULL string.

SELECT  
ENCODE('NULL', 'passwordstring'); 

Output:

NULL 
My Personal Notes arrow_drop_up
Recommended Articles
Page :