MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL CRC32() Function



The MySQL CRC32() function is used to compute a cyclic redundancy check value and returns a 32-bit unsigned value. It returns NULL if the argument is NULL. The argument is expected to be a string and (if possible) is treated as one if it is not.

Syntax

CRC32(expr)

Parameters

expr Required. Specify the string whose CRC32 value is to be retrieved.

Return Value

Returns the cyclic redundancy value.

Example 1:

The example below shows the usage of CRC32() function.

mysql> SELECT CRC32(10);
Result: 2707236321

mysql> SELECT CRC32('MySQL');
Result: 3259397556

mysql> SELECT CRC32('Learn SQL');
Result: 428816044

mysql> SELECT CRC32('');
Result: 0

mysql> SELECT CRC32(' ');
Result: 3916222277

mysql> SELECT CRC32(NULL);
Result: NULL

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCityAge
1JohnLondon25
2MarryNew York24
3JoParis27
4KimAmsterdam30
5RameshNew Delhi28

To get the cyclic redundancy value of all records of Name column of this table, the following query can be used:

SELECT *, CRC32(Name) AS CRC32_Value FROM Employee;

This will produce a result similar to:

EmpIDNameCityAgeCRC32_Value
1JohnLondon252437433000
2MarryNew York242256442705
3JoParis272520959417
4KimAmsterdam3078804536
5RameshNew Delhi282499654632
6SureshMumbai283267040966

❮ MySQL Functions