英文:
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<String> 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<String> result =
ctx.select(divlovs.asField())
.from(DIVLOVS)
.where(DIVLOVS.LOVART.eq(...))
.fetch();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论