CRC32() Function in MySQL
CRC32() function in MySQL is used to compute cyclic redundancy value. It returns NULL if the argument is NULL otherwise, it returns a 32-bit unsigned value after computing the redundancy.
Syntax :
CRC32(expr)
Parameter :
This method accepts only one parameter.
- expr –It is a string whose CRC32 value is to be retrieved.
Returns :
It returns cyclic redundancy value.
Example-1 :
Finding cyclic redundancy value for a string using CRC32 Function.
SELECT CRC32('geeksforgeeks') AS CRC_Value;
Output :
CRC_Value |
---|
114079174 |
Example-2 :
Finding cyclic redundancy value for a number using CRC32 Function.
SELECT CRC32( 2020 ) AS CRC_Value;
Output :
CRC_Value |
---|
2493804155 |
Example-3 :
Finding cyclic redundancy value for a NULL argument using CRC32 Function.
SELECT CRC32(NULL) AS CRC_Value;
Output :
CRC_Value |
---|
NULL |
Example-4 :
Using CRC32 Function to find cyclic redundancy value for a column data. To demonstrate, let us create a table named Player.
CREATE TABLE Player ( Player_id INT AUTO_INCREMENT, Player_name VARCHAR(100) NOT NULL, Playing_team VARCHAR(20) NOT NULL, PRIMARY KEY(Player_id ) );
Now, insert some data to the Player table.
INSERT INTO Player(Player_name, Playing_team) VALUES ('Virat Kohli', 'RCB' ), ('Rohit Sharma', 'MI' ), ('Dinesh Karthik', 'KKR' ), ('Shreyash Iyer', 'DC' ), ('David Warner', 'SRH' ), ('Steve Smith', 'RR' ), ('Andre Russell', 'KKR' ), ('Jasprit Bumrah', 'MI' ), ('Risabh Panth', 'DC' ) ;
So, the Player Table is as follows.
SELECT * FROM Player;
Output :
Player_id | Player_name | Playing_team |
---|---|---|
1 | Virat Kohli | RCB |
2 | Rohit Sharma | MI |
3 | Dinesh Karthik | KKR |
4 | Shreyash Iyer | DC |
5 | David Warner | SRH |
6 | Steve Smith | RR |
7 | Andre Russell | KKR |
8 | Jasprit Bumrah | MI |
9 | Risabh Panth | DC |
Now, we will find cyclic redundancy value for Player_name and Playing_team column using CRC32 Function.
SELECT *, CRC32(Player_name), CRC32(Playing_team) FROM Player;
Output :
Player_id | Player_name | Playing_team | CRC32 (Player_name) | CRC32 (Playing_team) |
---|---|---|---|---|
1 | Virat Kohli | RCB | 4234533515 | 3556712374 |
2 | Rohit Sharma | MI | 2696911654 | 185522819 |
3 | Dinesh Karthik | KKR | 703307832 | 359013669 |
4 | Shreyash Iyer | DC | 2817545593 | 974751956 |
5 | David Warner | SRH | 3645256088 | 1630650255 |
6 | Steve Smith | RR | 777202257 | 1278287345 |
7 | Andre Russell | KKR | 3090306698 | 359013669 |
8 | Jasprit Bumrah | MI | 191461017 | 185522819 |
9 | Risabh Panth | DC | 178998608 | 974751956 |
Please Login to comment...