【发布时间】:2021-06-11 22:59:01
【问题描述】:
我正在尝试为我的应用程序编写一些测试数据。 我要填充的表有一个字符串类型的列,其中包含一个 UUID。 我需要编写一个插入语句来填充此列。
我当前的语句几乎可以工作,但它为所有插入生成相同的 ID。生成的列不必是真正的 UUID,但必须在表中是唯一的。
我的陈述的简化版本如下所示:
SELECT
null as id,
whi.externalId,
(select lower(hex( randomblob(4)) || '-' || hex( randomblob(2))
|| '-' || '4' || substr( hex( randomblob(2)), 2) || '-'
|| substr('AB89', 1 + (abs(random()) % 4) , 1) ||
substr(hex(randomblob(2)), 2) || '-' || hex(randomblob(6)))) as GUID
FROM WorkHerdInventories as whi
这会导致以下结果:
【问题讨论】:
标签: sql sqlite random android-sqlite blob