Thursday, February 23, 2012

ORA-14452: attempt to create, alter or drop an index on temporary table already in use


Create temporary table with preserve rows on commit
SQL> create global temporary table temp_test (id number) on commit preserve rows;
Insert rows and commit

SQL> insert into temp_test values (1);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from temp_test;

         1


Try to drop temporary table
SQL> drop table temp_test;
drop table temp_test
           *
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already
in use

There is a lock on the temporary table

SQL> select * from v$lock
  2  where id1 in (select object_id from dba_objects
  3  where owner='DANCO'
  4  and object_name='TEMP_TEST');

000000008F004058 000000008F0040B0         25 TO      75757          1          3
         0        362          2


This is because the session is still keeping data in table.
To drop table you have first truncate data or exit from session

SQL> truncate table temp_test;

Table truncated.

SQL> drop table temp_test;

Table dropped.

4 comments: