rspec/rules/S2526/rule.adoc

53 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
Variables and fields declared as <code>NOT NULL</code> must be immediately initialized, since they cannot be implicitly initialized to <code>NULL</code>. This rule prevents <code>PLS-00218</code> exceptions from being raised at runtime.
== Noncompliant Code Example
----
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
----
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;
/
----