In SQL Server we can type IsNull() to determine if a field is null. Is there an equivalent function in PL/SQL?
views:
66answers:
3
+2
A:
You can use the condition if x is not null then.... It's not a function. There's also the NVL() function, a good example of usage here: http://www.techonthenet.com/oracle/functions/nvl.php
FrustratedWithFormsDesigner
2010-08-19 15:00:21
+2
A:
Instead of ISNULL, use NVL.
MS SQL:
SELECT ISNULL(SomeNullableField, 'If null, this value') FROM SomeTable
PL/SQL:
SELECT NVL(SomeNullableField, 'If null, this value') FROM SomeTable
BoltClock
2010-08-19 15:00:26
+5
A:
coalesce is supported in both Oracle and SQL Server and serves essentially the same function as nvl and isnull. (There are some important differences, coalesce can take an arbitrary number of arguments, and returns the first non-null one. The return type for isnull matches the type of the first argument, that is not true for coalesce, at least on SQL Server.)
Shannon Severance
2010-08-19 16:40:44
+1: `COALESCE` is ANSI, supported by Postgres, MySQL... The only caveat is that it doesn't necessarily perform as fast as native syntax.
OMG Ponies
2010-08-19 17:33:14
+1 for `COALESCE`, which has one important benefit over `NVL`: it does shortcut evaluation, whereas `NVL` always evaluates both parameters. Compare `COALESCE(1,my_expensive_function)` with `NVL(1,my_expensive_function)`.
Jeffrey Kemp
2010-08-20 04:17:50