In MariaDB, CRC32()
is a built-in numeric function that computes a cyclic redundancy check value and returns a 32-bit unsigned value.
CRC32 is a popular checksum algorithm used to detect data corruption.
Syntax
The syntax goes like this:
CRC32(expr)
Where expr
is expected to be a string and (if possible) is treated as one if it is not.
Example
Here’s an example:
SELECT CRC32('Cat');
Result:
+--------------+ | CRC32('Cat') | +--------------+ | 2786264392 | +--------------+
Here’s a comparison using different cases:
SELECT
CRC32('Cat'),
CRC32('CAT'),
CRC32('cat');
Result:
+--------------+--------------+--------------+ | CRC32('Cat') | CRC32('CAT') | CRC32('cat') | +--------------+--------------+--------------+ | 2786264392 | 150536482 | 2656977832 | +--------------+--------------+--------------+
Non-String Arguments
The argument is expected to be a string and (if possible) is treated as one if it is not.
Example:
SELECT
CRC32('10'),
CRC32(10);
Result:
+-------------+------------+ | CRC32('10') | CRC32(10) | +-------------+------------+ | 2707236321 | 2707236321 | +-------------+------------+
Null Arguments
CRC32()
returns null
if the argument is null
:
SELECT CRC32(null);
Result:
+-------------+ | CRC32(null) | +-------------+ | NULL | +-------------+
Missing Arguments
Calling CRC32()
with the wrong number of arguments, or without any arguments results in an error:
SELECT CRC32();
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CRC32'
And:
SELECT CRC32(10, 2);
Result:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'CRC32'