如何在HQL中模拟NVL [英] How to simulate NVL in HQL

查看:127
本文介绍了如何在HQL中模拟NVL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



I tried this:

from Table where (:par1 is null or col1 = :par1)

但是恰巧

but it happens that

from Table where :par1 is null

总是返回表的所有行,即使:par1不为空。

always returns all the rows of the table, even if the :par1 is not null.

同时

while

 select * from table where col1 = 'asdf'

不会返回任何行。

我无法使用本机语法,因为我的应用程序应该运行在不同的数据库引擎上。

I can't use native grammars because my application is supposed to run on different database engines

推荐答案

相当于HQL中的 nvl 命令是 coalesce 命令。 coalesce(a,b)将返回 a 如果 a 不是null,否则 b

The equivalent to the nvl command in HQL is the coalesce command. coalesce(a,b) will return a if a is not null, otherwise b.

所以你需要一些东西:

from Table where col1 = coalesce(:par1, 'asdf')

这篇关于如何在HQL中模拟NVL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆