Skip to Main Content
  • Questions
  • Please help, can't drop a corrupt table

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Ferko.

Asked: January 09, 2019 - 12:16 pm UTC

Last updated: May 09, 2022 - 2:31 pm UTC

Version: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Viewed 10K+ times! This question is

You Asked

Hi all,

we have a corrupt object named "TO_BE_DROPPED" in our development database. Previously it had a different name, but someone renamed it, because it cannot be deleted, only renamed. It cannot be dropped by any means we could find. Apparently the Oracle DB is not sure whether it is a normal table or a materialized view. This is what I tried:

DROP TABLE to_be_dropped
Error at line 1
ORA-32417: must use DROP MATERIALIZED VIEW LOG to drop "SCHEMA"."TO_BE_DROPPED"


and

DROP MATERIALIZED VIEW LOG ON to_be_dropped
Error at line 1
ORA-12002: there is no materialized view log on table "SCHEMA"."TO_BE_DROPPED"


and

DROP MATERIALIZED VIEW to_be_dropped
Error at line 1
ORA-12003: materialized view or zonemap "SCHEMA"."TO_BE_DROPPED" does not exist


Okay. After these attempts I tried creating an m-view log on the table. It works. But after dropping this m-view log, the table still remains. So I've created the m-view log again and also tried converting this table into a fully-fledged m-view by means of CREATE MATERIALIZED VIEW to_be_dropped ON PREBUILT TABLE... It works. After these steps, TOAD displays the object as a materialized view (originally the object was listed as an ordinary table). But when I drop the m-view, the table still remains!!

Ideas, anyone? Many thanks in advance! Even our DBAs couldn't help us get rid of this object.

and Chris said...

I'm not sure what's going on here. Contact support to see if they can help remove it.

Alternatively, here's something you could try:

- Export the schema excluding this object
- Drop the schema
- Re-import the schema

Or some other option where you rebuild your database/schema excluding this table/MV.

Rating

  (9 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

And what is the type of this object?

A reader, January 09, 2019 - 2:48 pm UTC


Hello,

What is the result of this query :
SELECT owner, object_type, status from dba_objects where object_name = 'TO_BE_DROPPED';


I ask that because you try to drop a table and after a materialized view log and after a materialized view. I think the first step is to be sure about the object's type and the schema.

And, after, try this, because if the object was built with a "weird" option, maybe it could be difficult to drop it.
If it is a table :
SELECT dbms_metadata.get_ddl('TABLE', 'TO_BE_DROPPED', 'the_owner') from dual;

and maybe your dba will see a solution.

Chris Saxon
January 09, 2019 - 2:53 pm UTC

Yep. I'm assuming there genuinely is something weird about this object. But it's worth checking the basics.

Missing bits

Ferko Mrkvicka, January 09, 2019 - 3:11 pm UTC

Some additional information, but it doesn't reveal much. That's why I didn't provide it in the original question. It gives the impression that TO_BE_DROPPED is an ordinary table.

SELECT owner, object_type, status from dba_objects where object_name = 'TO_BE_DROPPED';

>> SCHEMA, TABLE, VALID

DDL:

CREATE TABLE "SCHEMA"."TO_BE_DROPPED"
( "TEST" VARCHAR2(100)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SDATA01"
Chris Saxon
January 09, 2019 - 3:39 pm UTC

Yeah, I think you're going to have to go to support to resolve this. Or rebuild the schema!

YES!

David, January 09, 2019 - 3:28 pm UTC


You have a user called SCHEMA but it is a reserved word.
select count(*) from V$RESERVED_WORDS where keyword = 'SCHEMA';
COUNT(*)
-----------
1


Try this, with "" to escape the special word SCHEMA.
DROP TABLE "SCHEMA"."TO_BE_DROPPED";

Is it OK?
Chris Saxon
January 09, 2019 - 3:42 pm UTC

You can use reserved words - provided you quote them.

create table "TABLE" ( c1 int );

select table_name from user_tables
where  table_name = 'TABLE';

TABLE_NAME   
TABLE        

drop table "TABLE" purge;


And this doesn't explain why it only affects this table...

And no...

David, January 09, 2019 - 3:37 pm UTC

Sorry, I failed because I can create a user called SCHEMA.
SQL> create user SCHEMA identified by YukioYukio78964125;
Utilisateur cree.


But it is a reserved word... it's strange...

Renamed it...

David, January 09, 2019 - 4:28 pm UTC


Well, on Metalink I read that the problem is about the RENAME operation :
"Drop MATERIALIZED VIEW LOG on Table fails if Mview Log was Renamed (Doc ID 2435740.1)
The materialized log is huge and was renamed. After renaming that MLOG$_% Table, Drop Table / Drop Materialized view is reporting ORA- Errors."

I let TOM writes here the solution from the note because I read that it was not permitted to copy/past all a page from Metalink.

David
Connor McDonald
January 10, 2019 - 1:27 am UTC

Thanks for the input.

Yes - if you rename internal objects, then trouble will no doubt follow :-)

In 12c the workaround is to rename it back to its proper name, then drop:

rename mlog$_t_bkp to mlog$_t;
drop MATERIALIZED VIEW LOG on t;


R.I.P. cat

Racer I., January 10, 2019 - 7:25 am UTC

Hi,

Just out of curiosity I tried this :

create table t (ID NUMBER(1));

alter table t add constraint pk_t primary key (ID);

create materialized view log on t;

select * from dba_mview_logs where master = 'T';  

alter table MLOG$_T rename to OTHER; --5)

select * from dba_mview_logs where master = 'T';  

drop materialized view log on t; --1)

select * from dba_mview_logs where master = 'T'; --2)  

drop table other; --3)

alter table OTHER rename to MLOG$_T;

drop materialized view log on t; --4)


1) silently succeeds : even though MLOG$_T no longer existed to be dropped. Oracle didn't track the rename...
2) shows no result so everything's peachy?
3) fails with ORA-32417 : OTHER is still there, but cannot be dropped (probably a table flag not exposed in dba_tables)
4) fails with ORA-12002 : renaming doesn't help (connection is severed and you have no way to get rid of the orphan now)
5) I guess this should simply fail, same as with 3)

I guess the OP didn't do 1) while the table was named otherwise so 4) worked for them?

At first glance this seems to work :
create materialized view log on t;

select * from dba_mview_logs where master = 'T';  

drop materialized view log on t;

select * from dba_mview_logs where master = 'T';  

drop table MLOG$_T; -- ORA-32417

but it ultimately doesn't either because this creates and drops a new table MLOG$_T1 instead of picking up the existing one.

You'd need syntax similar to PRESERVE TABLE/USING for the mat view tables themselves.

This one fell into this trap too I guess :
https://community.oracle.com/thread/3652078

This was different in oracle 9 apparently :
https://community.oracle.com/thread/3731733
but not really better :
https://community.oracle.com/thread/3878770

regards,
Chris Saxon
January 10, 2019 - 10:42 am UTC

Looks like renaming the MV log table could be the culprit here. Nice investigation.

"SCHEMA" is not a real name

Ferko Mrkvicka, January 11, 2019 - 1:25 pm UTC

The user "SCHEMA" is just a replacement for a real schema name, because I didn't want to expose the real name publicly. I should've used MY_SCHEMA, though, to avoid confusion...
Chris Saxon
January 11, 2019 - 1:41 pm UTC

:)

Only export and import helped

Ferko Mrkvicka, February 12, 2019 - 7:51 am UTC

Finally the export and import helped. But I had to explicitly ask our DBAs to exclude that corrupt object from the export. At first I didn't do it and after the import this object was still corrupt (undroppable). So I asked the DBAs not to export that object, delete the entire schema, and then import it back, and that was the end of the TO_BE_DROPPED table/m-view. :)
Chris Saxon
February 12, 2019 - 10:46 am UTC

Thanks for letting us know, glad you solved this!

solved

mik, May 05, 2022 - 2:36 pm UTC

I have managed to drop such a table after clearing bit 65536 of property and bit 268435456 of trigflag in sys.tab$. Oracle version 12.1.0.2. Do not try to do this at home.
Chris Saxon
May 09, 2022 - 2:31 pm UTC

Do not try to do this at home.

Indeed!

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.