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:
EmpID | Name | City | Age |
---|---|---|---|
1 | John | London | 25 |
2 | Marry | New York | 24 |
3 | Jo | Paris | 27 |
4 | Kim | Amsterdam | 30 |
5 | Ramesh | New Delhi | 28 |
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:
EmpID | Name | City | Age | CRC32_Value |
---|---|---|---|---|
1 | John | London | 25 | 2437433000 |
2 | Marry | New York | 24 | 2256442705 |
3 | Jo | Paris | 27 | 2520959417 |
4 | Kim | Amsterdam | 30 | 78804536 |
5 | Ramesh | New Delhi | 28 | 2499654632 |
6 | Suresh | Mumbai | 28 | 3267040966 |
❮ MySQL Functions