rspec/rules/S2526/rule.adoc

55 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:07 +02:00
----
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
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:07 +02:00
----
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;
/
----