user2837961
user2837961

Reputation: 1555

ORA-06531 after Oracle upgrade

I upgraded my database from Oracle 10 to 11.2. The problem I face is that my geometry in tables don't work any more. My SQL is:

Select 
   GEOMETRYID, COORDCOUNT, CREATIONDATE, QUALITYID,       
  SDO_UTIL.TO_WKTGEOMETRY(SDO_CS.TRANSFORM(SDO_UTIL.SIMPLIFY(GEOMETRY, 1, 0.0000005), 27700)) as "WKT" 
FROM 
   NWKGEOMETRY 
WHERE 
   DELETIONDATE IS NULL;  
   AND SDO_GEOMETRY.GET_GTYPE(GEOMETRY)=2 AND SDO_UTIL.GETNUMVERTICES(GEOMETRY)>2;

and I get an error:

ORA-06531: Reference to uninitialized collection

If I remove TRANSFORM function then all works fine. What could be wrong?

Upvotes: 1

Views: 5250

Answers (1)

neshkeev
neshkeev

Reputation: 6476

This error:

ORA-06531: Reference to uninitialized collection

means that you have a collection that is not initialized before you use it, for example:

SQL> select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> ed
Wrote file afiedt.buf

  1  CREATE OR REPLACE TYPE t_employee AS OBJECT(
  2    id  number,
  3    name VARCHAR2(300),
  4    CONSTRUCTOR FUNCTION t_employee RETURN SELF AS RESULT
  5* )
SQL> /

Type created.

SQL> ed
Wrote file afiedt.buf

  1* CREATE OR REPLACE TYPE t_employees AS TABLE OF t_employee
SQL> /

Type created.

SQL> ed
Wrote file afiedt.buf

  1  DECLARE
  2    l_emp t_employee;
  3    l_emps t_employees;
  4  BEGIN
  5    for i in (SELECT employee_id, first_name
  6                FROM employees)
  7    loop
  8      l_emp := t_employee(i.employee_id, i.first_name);
  9      l_emps.extend();
 10      l_emps(l_emps.COUNT) := l_emp;
 11    end loop;
 12    DBMS_OUTPUT.put_line(l_emps(4).name);
 13* END;
SQL> /
DECLARE
*
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at line 9

As you can see, I have the ORA-06531 error, that's because I haven't initialized the l_emps variable, I have to add l_emps := t_employees();:

SQL> ed
Wrote file afiedt.buf

  1  DECLARE
  2    l_emp t_employee;
  3    l_emps t_employees;
  4  BEGIN
  5    l_emps := t_employees();
  6    for i in (SELECT employee_id, first_name
  7                FROM employees)
  8    loop
  9      l_emp := t_employee(i.employee_id, i.first_name);
 10      l_emps.extend();
 11      l_emps(l_emps.COUNT) := l_emp;
 12    end loop;
 13    DBMS_OUTPUT.put_line(l_emps(4).name);
 14* END;
SQL> /
David

PL/SQL procedure successfully completed.

So take a look at the sources of all these PL/SQL procedures, the problem is in them.

Upvotes: 2

Related Questions