NVL Function - PL/HQL Reference NVL function returns first non-NULL expression.
No. You have to use is null and is not null in HQL.
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 . So you would want something on the lines of: from Table where col1 = coalesce(:par1, 'asdf')
NVL and COALESCE are used to achieve the same functionality of providing a default value in case the column returns a NULL. The differences are: NVL accepts only 2 arguments whereas COALESCE can take multiple arguments. NVL evaluates both the arguments and COALESCE stops at first occurrence of a non-Null value.
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
.
So you would want something on the lines of:
from Table where col1 = coalesce(:par1, 'asdf')
If your underlying database is Oracle then you can use the nvl function, I tried it and it worked for me.
Query query = session.createQuery(
" select ft from FeatureToggle ft left outer join ft.featureToggleCustomerMap "
+ " ftcm where nvl(ftcm.custId,:custId) = :custId");
query.setParameter("custId", Long.valueOf(custId));
Your use case can be diffrent and you can use the nvl function as per your requirement if the database is nvl, not sure about the implecation of the other databases, as I have used this code only for Oracle. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With