views:

66

answers:

3

In SQL Server we can type IsNull() to determine if a field is null. Is there an equivalent function in PL/SQL?

+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
+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
+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
+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
+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