rules repository

G-4230

🆓
Warning

Always use a COALESCE instead of a NVL command, if parameter 2 of the NVL function is a function call or a SELECT statement.

Reason

The nvl function always evaluates both parameters before deciding which one to use. This can be harmful if parameter 2 is either a function call or a select statement, as it will be executed regardless of whether parameter 1 contains a null value or not.

The coalesce function does not have this drawback.

Example

Non-Compliant Example

select nvl(dummy,my_package.expensive_null(value_in => dummy))
  from dual;
Issues
LineColumnMessage
18Use COALESCE instead of NVL.

Compliant Solution - ★★★★★

select coalesce(dummy,my_package.expensive_null(value_in => dummy))
  from dual;

Parameters

Use parameters to customize the rule to your needs.

ParameterDescriptionDefault Value
DisableAllQuickFixComma-separated ist of rules for which a quick fix should not be applied to all the problems in a file.Core G-3130

References