If the not null restriction is added when varray is defined, the element of this varray cannot be null.
Definition:
Create or replace type integer_varray
As varray (5) of integer not null;
/
Then there is a PLSQL block as follows:
Declare
-- Declare and initialize a null set of rows.
Varray_integer integer_varray: = integer_varray ();
Begin
-- Loop through all records to print the varray contents.
For I in 1 .. varray_integer.limit Loop
-- Initialize row.
Varray_integer.extend;
/* No value assignment. If no value assignment is null, it should be compiled incorrectly. The result is compiled smoothly */
End loop;
-- Print to console how many rows are initialized.
Dbms_output.put ('integer varray initialized ');
Dbms_output.put_line ('[' | varray_integer.count | ']');
-- Varray_integer (1): = NULL;
For I in 1 .. varray_integer.count Loop
-- Print the contents.
Dbms_output.put ('integer varray ['| I |'] ');
Dbms_output.put_line ('[' | varray_integer (I) | ']');
If (varray_integer (I) is null) then
/* I thought this should not be executed, and the result will be printed */
Dbms_output.put_line ('integer varray ['| I |'] '|' is null ');
End if;
End loop;
End;
/
The running result is as follows:/* The running is normal, and the display element is null, which is a conflict of Definitions */
Integer varray initialized [5]
Integer varray [1] []
Integer varray [1] is null
Integer varray [2] []
Integer varray [2] is null
Integer varray [3] []
Integer varray [3] is null
Integer varray [4] []
Integer varray [4] is null
Integer varray [5] []
Integer varray [5] is null
The test environment is:
Banner
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
PL/SQL release 10.2.0.1.0-Production
Core 10.2.0.1.0 Production
TNS for 32-bit windows: Version 10.2.0.1.0-Production
Nlsrtl version 10.2.0.1.0-Production