How to get a cyclic redundancy check i.e CRC32() value in MySQL8 ?

With MySQL, we can do complex calculations very easily with the help of inbuilt mathematical functions. CRC32(str) helps in calculating the cyclic redundancy check value and returns a 32-bit unsigned value.

Now let’s start with it.


CRC32(str) is a mathematical function. CRC means cyclic redundancy check.

cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.

Computes a cyclic redundancy check value and returns a 32-bit unsigned value. The argument is expected to be a string and (if possible) is treated as one if it is not.

If the argument is not a string, MySQL treats it as one anyway (either that, or you’ll get an error).

It returns the CRC of input string str. Where str is the argument, whose value will be passed by the user.

It will return NULL, if str is passed as NULL.


MySQL CRC32() : Syntax

CRC32 ( X );

MySQL CRC32() : Parameter

Name, Required /Optional, Description
str , Required, A string whose CRC32 value is to be fetched.


MySQL CRC32() : Output

Return, Description
NULL, if the argument is NULL.
It returns 32-bit unsigned value cyclic redundancy value of input string.


MySQL CRC32()  Available from : MySQL 4.1


CRC32() Example 1 : Basic Examples

See the below example. See the output, when ‘www.tutorialmines.net’ is passed.

mysql> SELECT CRC32('www.tutorialmines.net') AS 'crc value';
+------------+
| crc value |
+------------+
| 2600963911 |
+------------+
1 row in set (0.00 sec)

Now, Let’s change the input value to 56456. See what it returns.

mysql> SELECT CRC32(56456) AS 'crc value';
+-----------+
| crc value |
+-----------+
| 877297141 |
+-----------+
1 row in set (0.00 sec)

CRC32() Example 2 : Using it with PI()

We are using the PI() function to get the value of CRC32() with it. I get the below value.

mysql> SELECT CRC32(PI()) AS 'crc value';
+------------+
| crc value |
+------------+
| 2969982827 |
+------------+
1 row in set (0.00 sec)

CRC32() Example 3 : Case Sensitivity

Here you can see the different results on the basis of the case of your arguments.

mysql> SELECT CRC32('TUTORIALMINES'), 
              CRC32('Tutorialmines'), 
              CRC32('TutorialMINES');
+------------------------+------------------------+------------------------+
| CRC32('TUTORIALMINES') | CRC32('Tutorialmines') | CRC32('TutorialMINES') |
+------------------------+------------------------+------------------------+
| 1993232533             | 3824949637             | 346610485 |
+------------------------+------------------------+------------------------+
1 row in set (0.00 sec)

CRC32() Example 4 : NULL arguments

If the argument is NULL, it will return NULL. See the below example :

mysql> SELECT CRC32(NULL) AS 'crc value';
+-----------+
| crc value |
+-----------+
| NULL |
+-----------+
1 row in set (0.00 sec)

Related articles : PI(), COS(), MySQL Maths.

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago