gpt4 book ai didi

mysql - 插入后获取 UUID() 的值?

转载 作者:行者123 更新时间:2023-11-30 23:34:08 26 4
gpt4 key购买 nike

我正在使用 JDBC + mysql。我正在插入一条记录并在我的语句中使用 UUID() 。我想知道我们是否可以从 ResultSet 中获取生成的 UUID 值?:

PreparedStatement stmt = conn.prepareStatement("INSERT INTO foo(name, random),
VALUES(john, UUID())");
ResultSet generatedKeys = stmt.getGeneratedKeys();
// any way to find out the value of the UUID() result?

是的,所以我只是想知道我是否可以获得上面 UUID() 生成的任何值而无需再次选择记录。

谢谢

最佳答案

尝试设置和选择用户变量,例如-

SET @uuid = UUID();
INSERT INTO foo(name, random) VALUES(john, @uuid);
SELECT @uuid;

关于mysql - 插入后获取 UUID() 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com