Truncate table in Oracle getting errors

后端 未结 9 1283
忘了有多久
忘了有多久 2021-02-02 08:11

I got the problem is when I run following command in Oracle, I encounter the error.

Truncate table mytable;

Errors:

         


        
9条回答
  •  星月不相逢
    2021-02-02 08:52

    You have to swap the TRUNCATE statement to DELETE statements, slower and logged but that's the way to do it when constraints are in place.

    DELETE mytablename;
    

    Either that or you can find the foreign keys that are referencing the table in question and disable them temporarily.

    select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||CONSTRAINT_NAME||';'
    from user_constraints
    where R_CONSTRAINT_NAME='';
    

    Where pk-of-table is the name of the primary key of the table being truncated

    Run the output of the above query. When this has been done, remember to enable them again, just change DISABLE CONSTRAINT into ENABLE CONSTRAINT

提交回复
热议问题