MySQL | CRC32 method
Start your free 7-days trial now!
MySQL's CRC32(~)
method computes a cyclic redundancy check value and returns a 32-bit unsigned value.
Cyclic redundancy check is a technique used to detect accidental changes to raw data. A sequence of check bits are appended to the data to be transferred, which makes the resulting sequence exactly divisible by a pre-defined binary number. The recipient of this data will also perform division with the pre-defined binary number. If it does not have any remainder, the data is assumed to be intact.
Parameters
1. expr
| string
The string to compute cyclic redundancy check value for.
Return value
A 32-bit unsigned cyclic redundancy check value.
Examples
Basic usage
To compute cyclic redundancy check value for 'hello'
:
SELECT CRC32('hello');
+----------------+| CRC32('hello') |+----------------+| 907060870 |+----------------+
Case sensitivity
The computation of cyclic redundancy check value is case sensitive:
SELECT CRC32('test'), CRC32('Test');
+---------------+---------------+| CRC32('test') | CRC32('Test') |+---------------+---------------+| 3632233996 | 2018365746 |+---------------+---------------+
Numbers are treated as a string
To compute cyclic redundancy check value for 30
and '30'
:
SELECT CRC32(30), CRC32('30');
+------------+-------------+| CRC32(30) | CRC32('30') |+------------+-------------+| 2473281379 | 2473281379 |+------------+-------------+
We can see that both inputs yield the same result.
NULL values
NULL
inputs return NULL
:
SELECT CRC32(NULL);
+-------------+| CRC32(NULL) |+-------------+| NULL |+-------------+