Question about varray's not null in Oracle

Source: Internet
Author: User

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

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.