Jump to: navigation, search

Mysql DECODE

From w3cyberlearnings

Contents

MySQL DECODE Function

This function decrypts the encrypted string that created by using pass_str as the password in ENCODE() function.

Syntax DECODE

  • encrypted string: string that encrypted
  • pass_str: password used to encrypted the string
DECODE(encrypted string, pass_str);

Note

When encrypt and decrypt, the pass_str password must be the same.

Example 1

mysql> SET @test=ENCODE('good','pass_secret');
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @test;
+-------+
| @test |
+-------+
| �C�  | 
+-------+
1 row in set (0.00 sec)

mysql> SELECT DECODE(@test,'pass_secret');
+-----------------------------+
| DECODE(@test,'pass_secret') |
+-----------------------------+
| good                        | 
+-----------------------------+
1 row in set (0.00 sec)

Example 2


mysql> INSERT INTO userpassword(username, password)
    -> VALUES('Bating',ENCODE('password123','pass_secret'));
Query OK, 1 row affected (0.00 sec)

mysql> SELECT username,DECODE(password,'pass_secret') FROM userpassword;
+----------+--------------------------------+
| username | DECODE(password,'pass_secret') |
+----------+--------------------------------+
| Bating   | password123                    | 
+----------+--------------------------------+
1 rows in set (0.01 sec)

mysql> SELECT * FROM userpassword WHERE password=ENCODE('password123','pass_secret');
+----+----------+-------------+
| id | username | password    |
+----+----------+-------------+
|  2 | Bating   | HE��H�����1 | 
+----+----------+-------------

Related Links


Navigation
Web
SQL
MISC
References