在 SQL 语句中调用带有默认值的函数。

huangapple go评论64阅读模式
英文:

Call a function with default value in an SQL statement

问题

我有这个SQL语句:

select pa_bez.divlovs(lovart, lovid) bez, lovid, lovart from divlovs where lovart = ?

pa_bez.divlovs 有一个带有默认值的第三个参数。

jOOQ 生成了这个方法:

public static Field<String> divlovs(String pLovart, String pLovid, String pSprache)

如果我在SELECT语句中使用这个方法,我将不得不传递null,而默认值将不会被使用。

我该如何将这个查询转换为 jOOQ,使得 pa_bez.divlovs 仅以两个参数调用?

英文:

I have this SQL statement:

select pa_bez.divlovs(lovart, lovid) bez, lovid, lovart from divlovs where lovart = ?

pa_bez.divlovs has a third parameter with a default value.

jOOQ generated this method:

public static Field&lt;String&gt; divlovs(String pLovart, String pLovid, String pSprache)

If I use this in the SELECT statment I'll have to pass null and the default value will not used.

How can I translate this query to jOOQ that pa_bez.divlovs is called with only two parameters?

答案1

得分: 2

你不能使用 static 便捷方法来应用默认值,如果你想要应用默认值,你需要使用底层的 Routine 对象,例如:

Divlovs divlovs = new Divlovs();
divlovs.setPLovart(...);
divlovs.setPLovid(...);

List<String> result =
ctx.select(divlovs.asField())
   .from(DIVLOVS)
   .where(DIVLOVS.LOVART.eq(...))
   .fetch();
英文:

You cannot use the static convenience method if you want to apply the default, you'll have to use the underlying Routine object, e.g.

Divlovs divlovs = new Divlovs();
divlovs.setPLovart(...);
divlovs.setPLovid(...);

List&lt;String&gt; result =
ctx.select(divlovs.asField())
   .from(DIVLOVS)
   .where(DIVLOVS.LOVART.eq(...))
   .fetch();

huangapple
  • 本文由 发表于 2020年10月20日 17:31:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64442350.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定