Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL adding dashes to UUID in a table

Tags:

uuid

mysql

Is there a easy way to convert UUIDs from this format

5967ca5e6162317eb4a825dcdcde0aea

to this format?

5967ca5e-6162-317e-b4a8-25dcdcde0aea

with an MySQL Query? i need to convert over 1000 UUIDs

like image 977
Arusu Avatar asked Dec 08 '22 05:12

Arusu


1 Answers

SET @x = '5967ca5e6162317eb4a825dcdcde0aea';

SELECT CONCAT_WS('-',MID(@x,1,8),MID(@x,9,4),MID(@x,13,4),MID(@x,17,4),MID(@x,21,1000))n;
+--------------------------------------+
| n                                    |
+--------------------------------------+
| 5967ca5e-6162-317e-b4a8-25dcdcde0aea |
+--------------------------------------+
like image 156
Strawberry Avatar answered Dec 11 '22 10:12

Strawberry