rspec/rules/S2526/rule.adoc

57 lines
1.3 KiB
Plaintext

== Why is this an issue?
Variables and fields declared as ``++NOT NULL++`` must be immediately initialized, since they cannot be implicitly initialized to ``++NULL++``. This rule prevents ``++PLS-00218++`` exceptions from being raised at runtime.
=== Noncompliant code example
[source,text]
----
SET SERVEROUTPUT ON
DECLARE
test PLS_INTEGER; -- This variable is implicitly initialized to NULL
foo PLS_INTEGER NOT NULL; -- Noncompliant PLS-00218 a variable declared NOT NULL must have an initialization assignment
TYPE myType IS RECORD(
foo PLS_INTEGER NOT NULL, -- Non-Compliant PLS-00218 a variable declared NOT NULL must have an initialization assignment
bar PLS_INTEGER NULL
);
BEGIN
IF test IS NULL
DBMS_OUTPUT.PUT_LINE('test is NULL');
ELSE
DBMS_OUTPUT.PUT_LINE('test is NOT NULL');
END IF;
END;
/
----
=== Compliant solution
[source,text]
----
SET SERVEROUTPUT ON
DECLARE
test PLS_INTEGER; -- This variable is implicitly initialized to NULL
foo PLS_INTEGER NOT NULL := 42; -- Compliant
TYPE myType IS RECORD(
foo PLS_INTEGER NOT NULL := 42, -- Compliant
bar PLS_INTEGER NULL
);
BEGIN
IF test IS NULL
DBMS_OUTPUT.PUT_LINE('test is NULL');
ELSE
DBMS_OUTPUT.PUT_LINE('test is NOT NULL');
END IF;
END;
/
----