深圳全飞鸿

标题: MYSQL 生成UUID() 即 ORACLE 中的guid()函数 [打印本页]

作者: zhgc    时间: 2019-7-7 14:34
标题: MYSQL 生成UUID() 即 ORACLE 中的guid()函数
MYSQL 生成UUID 即 guid 函数
-- 带 - 的UUID
  1. select UUID()
复制代码


-- 去掉 - 的UUID
  1. select replace(uuid(),'-','')
复制代码


uuid()产生的是36位字符串,用uuid_short() 不带杠,长度短,而且短时间情况下是连续递增的

观察规律:

  1. select uuid(), 0
  2. union
  3. select uuid(), sleep(.001)
  4. union
  5. select uuid(), sleep(.010)
  6. union
  7. select uuid(), sleep(.100)
  8. union
  9. select uuid(), sleep(1)
  10. union
  11. select uuid(), sleep(10)
  12. union
  13. select uuid(), 0;
复制代码


在观察:

select uuid_short(), 0
union
select uuid_short(), sleep(.001)
union
select uuid_short(), sleep(.010)
union
select uuid_short(), sleep(.100)
union
select uuid_short(), sleep(1)
union
select uuid_short(), sleep(3)
union
select uuid_short(), 0;

26213689065472111 0
26213689065472112 0
26213689065472113 0
26213689065472114 0
26213689065472115 0
26213689065472116 0
26213689065472117 0






欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2