RE: Interesting difference between nvl() and coalesce()

From: Mark W. Farnham <>
Date: Sun, 8 Dec 2019 10:37:00 -0500
Message-ID: <082f01d5addd$55231d80$ff695880$>

As for repairing your code, if a bit of code is only valid for an inbound null argument, that check for is not null turning the guts into a no-op is the cohesive solution (also known in ancient times as a "firewall."). You can do that with a wrapper and protect the fragile function within a package body or use a wide variety of ways to project the fragility, or you can do it in the function. Try to avoid doing it twice (or n) though: repetitive firewalls instead of encapsulation can become significant and might underflow routine detection in profilers despite being wasteful in aggregate. Avoid also replicating the "if is not null" inline source code wrapper, which is an example of writing redundant "sprinkled all over" application code that retains the overhead even after the function is encapsulated.

THE PRECISE formulation of where to put "firewalls" has in the past been something of a religious war. I am agnostic on that religious war other than holding it should be done a single way in a given application suite.


-----Original Message-----
From: [] On Behalf Of Stefan Koehler Sent: Sunday, December 08, 2019 3:26 AM
Cc: oracle-l-freelists
Subject: Re: Interesting difference between nvl() and coalesce()

Hello Stefan,
ah OK. Just to get the complete picture, please be also aware about the impact on the CBO if you gonna change the code.

Best Regards
Stefan Koehler

Independent Oracle performance consultant and researcher Website:
Twitter: _at_OracleSK

> Stefan Knecht <> hat am 8. Dezember 2019 um 09:20 geschrieben:
> Perhaps to add a bit of detail - here it wasn't just a performance thing. It literally broke the code, because we have logic in the function that's called in the second argument of nvl(), and that logic is only valid if the first argument that came in, was indeed NULL.
> Sigh.


Received on Sun Dec 08 2019 - 16:37:00 CET

Original text of this message