Open In App

CRC32() Function in MySQL

Last Updated : 05 Oct, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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_idPlayer_namePlaying_team
1Virat KohliRCB
2Rohit SharmaMI
3Dinesh KarthikKKR
4Shreyash IyerDC
5David WarnerSRH
6Steve SmithRR
7Andre RussellKKR
8Jasprit BumrahMI
9Risabh PanthDC
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_idPlayer_namePlaying_teamCRC32 (Player_name)CRC32 (Playing_team)
1Virat KohliRCB 42345335153556712374
2Rohit SharmaMI 2696911654185522819
3Dinesh KarthikKKR703307832359013669
4Shreyash IyerDC2817545593974751956
5David WarnerSRH36452560881630650255
6Steve SmithRR7772022571278287345
7Andre RussellKKR3090306698359013669
8Jasprit BumrahMI191461017185522819
9Risabh PanthDC178998608974751956

Next Article
Article Tags :

Similar Reads