MySQL IS_UUID() Function
In MySQL, the IS_UUID() function checks whether a given string is a valid UUID string.
UUIDs are usually generated using the UUID() function. A valid UUID string should be in the following format:
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
or
aaaaaaaabbbbccccddddeeeeeeeeeeee
IS_UUID() Syntax
Here is the syntax of the MySQL IS_UUID() function:
IS_UUID(string)
Parameters
string- Required. String to check.
Return value
The MySQL IS_UUID() function will return if 1 the given string is in UUID string format, otherwise return 0.
This function only checks whether the string conforms to the UUID string format, regardless of whether or not it was actually produced by the UUID() function.
IS_UUID() Examples
Here is the basic usage of MySQL IS_UUID() function.
SELECT IS_UUID('d114115a-ce6a-11ec-8607-63ec778e6346');
+-------------------------------------------------+
| IS_UUID('d114115a-ce6a-11ec-8607-63ec778e6346') |
+-------------------------------------------------+
| 1 |
+-------------------------------------------------+SELECT IS_UUID('d114115ace6a11ec860763ec778e6346');
+---------------------------------------------+
| IS_UUID('d114115ace6a11ec860763ec778e6346') |
+---------------------------------------------+
| 1 |
+---------------------------------------------+If a string does not conform to the UUID string format, the IS_UUID() function will return 0, for example:
SELECT IS_UUID('123'), IS_UUID('abcdefeg');
+----------------+---------------------+
| IS_UUID('123') | IS_UUID('abcdefeg') |
+----------------+---------------------+
| 0 | 0 |
+----------------+---------------------+