Skip to main content

Variables and RECORD fields do not need to be initialized with NULL

ZPA rule for PL/SQL and Oracle SQL · VariableInitializationWithNull

A variable or record field declared without a default value starts as null. Initializing it with NULL, or with '', which Oracle treats as null, repeats the default and makes the reader look for a reason that does not exist.

This rule reports a variable or record field initialized with NULL or '', through := or DEFAULT. A parameter's default is not reported: DEFAULT NULL there makes the parameter optional.

Examples​

Noncompliant Code Example
declare
l_label varchar2(30) := null; -- Noncompliant
type t_slot is record (code varchar2(10) default ''); -- Noncompliant
begin
l_label := slot_label(42);
end;
Compliant Solution
declare
l_label varchar2(30);
type t_slot is record (code varchar2(10));
begin
l_label := slot_label(42);
end;