== Why is this an issue?

``++NVL++`` was introduced by Oracle Database during the 80's. ``++COALESCE++`` is a more modern function part of ANSI-92 standard than can replace ``++NVL++``. Use of ``++COALESCE++`` should be preferred to ``++NVL++`` for performance reason if the two parameters provided have the same type. COALESCE is running faster than NVL thanks to its short-circuit evaluation of the parameters.

In order to avoid "ORA-00932: inconsistent datatypes" error, double-check the two arguments of the NVL function have the same type before switching to COALESCE.


=== Noncompliant code example

[source,sql]
----
SELECT employee_uuid, NVL(TO_CHAR(bonus_pct), 'not this year') "Bonus" FROM employees
----


=== Compliant solution

[source,sql]
----
SELECT employee_uuid, COALESCE(TO_CHAR(bonus_pct), 'not this year') "Bonus" FROM employees
----



ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

=== on 3 Apr 2018, 09:12:44 Alexandre Gigleux wrote:
It has been decided to not implement this rule because the performance gain to move to COALESCE is not guaranteed.

Example: \https://jonathanlewis.wordpress.com/2018/02/13/coalesce-v-nvl/

endif::env-github,rspecator-view[]
