如果在定义VARRAY的时候带上NOT NULL限制,那么这个VARRAY的元素就不能为NULL.
如下定义:
CREATE OR REPLACE TYPE integer_varray
AS VARRAY(5) OF INTEGER NOT NULL;
/
然后有一个PLSQL块如下:
-- 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;
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
dbms_output.put_line('Integer Varray ['||i||'] '|| 'is null');
end if;
END LOOP;
END;
/
运行结果如下:
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
测试环境为:
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