©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMariaDB

MariaDB DECODE SQL Function - Decrypt string with password

DECODESyntax:DECODE(Binary string, Password)
Return value:CHAR
Function type:Encryption & Compression
Function Description

The DECODE() function decodes a "Binary string" with "password".

As a result, a character string that was previously encrypted is returned.

Numeric values ​​in the "Password" argument are interpreted as a character string.

If "Binary string" contains no characters, an empty string is returned.

If the value of the "Binary string" or "Password" argument is NULL, the DECODE() function returns NULL.


To encode a character string, the ENCODE() function can be chosen.


Starting with MariaDB version 10.3.2, when Oracle mode is enabled, this function works like the DECODE_ORACLE() function.

This feature is not present in MySQL 8.0.

SQL Examples for the DECODE function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

select decode(unhex('15C81E87'), 'Password');
select decode(unhex('D5E8E316C9D9'), 'Password');
select decode(unhex('D357DDEAA0E3'), 789);

select decode(unhex('BE26F8C1'), '');
select decode('''Password');
select decode(null'Password');
select decode(unhex('BE26F8C1'), null);

decode(unhex('15C81E87'), 'Password')
varchar(4) BINARY
Test
decode(unhex('D5E8E316C9D9'), 'Password')
varchar(6) BINARY
123456
decode(unhex('D357DDEAA0E3'), 789)
varchar(6) BINARY
123456
decode(unhex('BE26F8C1'), '')
varchar(4) BINARY
Test
decode('', 'Password')
varchar(0) BINARY
 
decode(null, 'Password')
varchar(0) BINARY
NULL
decode(unhex('BE26F8C1'), null)
varchar(4) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the DECODE() function in MariaDB databases

In MariaDB, the DECODE() function can be used to decode encrypted binary strings using a specified password. The result ist a string. The function is used to decode strings previously encoded with the ENCODE() function. It is not a general decoding function.

In ORACLE mode starting with MariaDB version 10.3.2, the function transforms or replaces values ​​based on a set of conditions. The function takes an expression as the first argument, followed by search values ​​and the corresponding results, compares the expression to the set of conditions and returns the result based on the first match. If no match is found, the default result is returned. The function can be used in this way to convert or map one value to another based on specified conditions. When MariaDB is not running in ORACLE mode, this type of function is made available called DECODE_ORACLE().
DAYOFMONTHDAYOFWEEKDAYOFYEARDECODEDECODE_ORACLEDEFAULTDEGREES

Further MySQL und MariaDB SQL Encryption & Compression

AES_DECRYPTAES_DECRYPT(String, Key)
More about AES_DECRYPT Function

AES_ENCRYPTAES_ENCRYPT(String, Key)
More about AES_ENCRYPT Function

COMPRESSCOMPRESS(String)
More about COMPRESS Function

DES_DECRYPTDES_DECRYPT(Binary string [, Key])
More about DES_DECRYPT Function

DES_ENCRYPTDES_ENCRYPT(String [, Key])
More about DES_ENCRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE Function

ENCRYPTENCRYPT(String [, Salt])
More about ENCRYPT Function

FROM_BASE64FROM_BASE64(String)
More about FROM_BASE64 Function

MD5MD5(String)
More about MD5 Function

OLD_PASSWORDOLD_PASSWORD(String)
More about OLD_PASSWORD Function

PASSWORDPASSWORD(String)
More about PASSWORD Function

RANDOM_BYTESRANDOM_BYTES(Length)
More about RANDOM_BYTES Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 Function

TO_BASE64TO_BASE64(String)
More about TO_BASE64 Function

UNCOMPRESSUNCOMPRESS(Binary string)
More about UNCOMPRESS Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the DECODE SQL function: mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer