将函数指定为JOOQ中的值
使用JOOQ,我想在插入过程中指定字段的值。
在SQL Server中,等效查询是:
插入表(a,t)value('foo',sysdateetime())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
使用JOOQ,我想在插入过程中指定字段的值。
在SQL Server中,等效查询是:
插入表(a,t)value('foo',sysdateetime())
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
将绑定值与表达式混合:
假设您使用生成的代码,编写以下内容:
values()
条款仅具有2个重载:它没有过多加载,因为会有一个所需过载的指数数量。因此,这里要做的关键是要包裹您的绑定变量使用
dsl.val()
显式。另请参阅此问题:
如何创建一个字段< t>从jooq中的值t明确?
sysdateTime
jooq上的注释支持标准SQL
current_timestamp
通过 。如果您喜欢使用sysdateTime
,则可以创建 plain sql模板为此,或使用dsl.function()
Mixing bind values with expressions:
Assuming you're using generated code, write this:
The
VALUES()
clause only has 2 overloads:It doesn't have an overload mixing both things, because there would be an exponential number of needed overloads. So the key thing to do here is to wrap your bind variables using
DSL.val()
explicitly.See also this question:
How do I create a Field<T> from a value T in jOOQ, explicitly?
A note on
SYSDATETIME
jOOQ supports the standard SQL
CURRENT_TIMESTAMP
expression viaDSL.currentTimestamp()
andDSL.currentLocalDateTime()
. If you prefer usingSYSDATETIME
, you can create a plain SQL template for that, or useDSL.function()