Open In App

IS_UUID() function in MySQL

Last Updated : 16 Dec, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
This function in MySQL is used to check whether the given Universal Unique Identifier (UUID) is valid or not. It returns 1 if the argument is a valid string-format UUID, 0 if the argument is not a valid UUID, and NULL if the argument is NULL. The following are the valid string-format UUID in MySQL :
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
aaaaaaaabbbbccccddddeeeeeeeeeeee
{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}
Syntax :
IS_UUID(string_uuid) 
Parameter : This method accepts one parameter.
  • string_uuid - Input UUID which we want to check.
Returns : It returns 1 if the UUID is valid and 0 if it is non valid. Example-1 : Checking whether the given Universal Unique Identifier value is valid or not with the help of UUID Function. As it is in one of the 3 valid string format we will get 1 in result. We can see that given UUID is in 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' format.
SELECT IS_UUID('3aad549b-acbd-4318-6498-3b0a656024bc') 
AS ValidOrNot;
Output :
VALIDORNOT
1
Example-2 : Checking whether the given Universal Unique Identifier value is valid or not with the help of UUID Function. As it is in one of the 3 valid string format we will get 1 in result. We can see that given UUID is in 'aaaaaaaabbbbccccddddeeeeeeeeeeee ' format.
SELECT IS_UUID('1cda554accab231487411a9a656824cc') 
AS ValidOrNot;
Output :
VALIDORNOT
1
Example-3 : Checking whether the given Universal Unique Identifier value is valid or not with the help of UUID Function. As it is in one of the 3 valid string format we will get 1 in result. We can see that given UUID is in '{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}' format.
SELECT IS_UUID('{9dcd767a-ccaa-1532-3245-5b8c874124aa}') 
AS ValidOrNot;
Output :
VALIDORNOT
1
Example-4 : Checking whether the given Universal Unique Identifier value is valid or not with the help of UUID Function. As it is not in one of the 3 valid string format we will get 0 in result.
SELECT IS_UUID('7acd798c-daba-6731-4123-8b8c7751') 
AS ValidOrNot;
Output :
VALIDORNOT
0
Example-5 : Checking whether the result given by RAND() function is a valid Universal Unique Identifier or not with the help of UUID Function.
SELECT IS_UUID(RAND()) 
AS ValidOrNot;
Output :
VALIDORNOT
0
So, we can see the result given by RAND() function is not a valid UUID.

Next Article
Article Tags :

Similar Reads