MySQL adding dashes to UUID in a table

青春壹個敷衍的年華 提交于 2019-12-23 20:18:07

问题


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


回答1:


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 |
+--------------------------------------+


来源:https://stackoverflow.com/questions/27039152/mysql-adding-dashes-to-uuid-in-a-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!