nvl

Why does NVL always evaluate 2nd parameter

Does anyone know, why Oracle's NVL (and NVL2) function always evaluate the second parameter, even if the first parameter is not NULL? Simple test: CREATE FUNCTION nvl_test RETURN NUMBER AS BEGIN dbms_output.put_line('Called'); RETURN 1; END nvl_test; SELECT NVL( 0, nvl_test ) FROM dual returns 0, but also prints Called. nvl_tes...

NULL handling with subselect in Hibernate Criteria API

I'm constructing a Hibernate Criterion, using a subselect as follows DetachedCriteria subselect = DetachedCriteria.forClass(NhmCode.class, "sub"); // the subselect selecting the maximum 'validFrom' subselect.add(Restrictions.le("validFrom", new Date())); // it should be in the past (null needs handling here) subselect.add(Property.f...

Not sure how to use Decode, NVL, and/or isNull (or something else?) in this situation

I have a table of orders for particular products, and a table of products that are on sale. (It's not ideal database structure, but that's out of my control.) What I want to do is outer join the order table to the sale table via product number, but I don't want to include any particular data from the sale table, I just want a Y if the jo...

Coalesce equivalent in Hibernate Criteria query?

Hi everyone, I want to write the following query as a Hibernate Criteria query: select to_char(nvl(ol.updated_datetime, ol.created_datetime), 'dd/mm/yyyy'), sum(discount_price) from order_line ol where nvl(ol.updated_datetime, ol.created_datetime) between to_date('05-may-10') and to_date('30-may-10') group by to_cha...

Using NVL function in SQL, please help!

I'm needing to select first and last name in a table which is working fine in the following SQL, but the part that isn't working is the NVL function. The file should show all pilots at a company that fly helicopters and IF they don't have a licence the field HT_NAME should come up as 'N/A' and the field for end hours flown should be 0. I...