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.)
Videos
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.)
Instead of ISNULL(), use NVL().
T-SQL:
SELECT ISNULL(SomeNullableField, 'If null, this value') FROM SomeTable
PL/SQL:
SELECT NVL(SomeNullableField, 'If null, this value') FROM SomeTable
Your first CASE expression won't even compile, but if we make a small change then it will:
CASE s.COURSE_SCHEDULED_ID
WHEN NULL THEN 'false'
ELSE 'true'
END AS "Is scheduled?"
This will be evaluated as this:
CASE WHEN s.COURSE_SCHEDULED_ID = NULL
THEN 'false'
ELSE 'true'
END AS "Is scheduled?"
Note very carefully that the COURSE_SCHEDULED_ID is being compared to NULL using the equality operator. This won't work as expected with NULL. Instead, for NULL checks the second verbose version always must be used as it allows IS NULL and IS NOT NULL checks.
From the documentaion:
In a simple
CASEexpression, Oracle Database searches for the firstWHEN ... THENpair for which expr is equal to comparison_expr and returns return_expr. If none of theWHEN ... THENpairs meet this condition, and anELSEclause exists, then Oracle returns else_expr. Otherwise, Oracle returns null.
In you first version you have
CASE s.COURSE_SCHEDULED_ID WHEN IS NULL THEN
which will throw "ORA-00936: missing expression" because IS NULL is a condition, not a value or expression. So then you might think you could do:
CASE s.COURSE_SCHEDULED_ID WHEN NULL THEN
but that will go to the else value because the comparison is "expr is equal to comparison_expr", and nothing is equal to (or not equal to) null (documentation).
In your second version you now have a searched case expression:
In a searched
CASEexpression, Oracle searches from left to right until it finds an occurrence of condition that is true, ...
Now it is expecting a condition (rather than a value or expression), so s.COURSE_SCHEDULED_ID IS NULL can be evaluated and is true.