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;
/