ORA-06531: References uninitialized collection issues resolved

Source: Internet
Author: User

Today, the debugging stored procedure "ORA-06531: Reference uninitialized Collection" error, carefully looked for a Metalink, found that the need to initialize, and the previous use of the table structure has not been initialized this step, the reason is that the declaration method is not declared in the form of a table, but a field manually written by myself. First cold one!
----------------

We can see from Metalink that this type should be used as follows:

-- Create employee_type
Create or replace type employee_type as object (
Empid number,
Empname varchar2 (20 ),
Job varchar2 (20 ));
/
-- Create employee_tab_type
Create or replace type employee_tab_typeTableOf employee_type;
/
-- Create department_type -- using employee_tab_type
Create or replace type department_type as object (
Deptid number,
Deptname varchar2 (20 ),
Deptlocation varchar2 (20 ),
Emp_tab employee_tab_type );
/

Declare

/* Initialize the collection, else you will get ORA-06531: Reference to uninitialized Collection */

My_emp employee_tab_type: = employee_tab_type ();
My_dept department_type;
Begin
My_emp.extend; -- this parameter must be specified. Otherwise, the pointer out of bounds is reported.
My_emp (1): = employee_type (2, 'savitha ', 'mgr'); -- if it is a record, you can assign the value of employee_type directly.
My_dept: = department_type (1, 'Research ', 'India', my_emp );
End;

/

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.