Truncate table in Oracle getting errors

后端 未结 9 1432
忘了有多久
忘了有多久 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 09:08

    I had the similar issue and I sorted it out by the following scripts.

    begin
    for i in (select constraint_name, table_name from user_constraints a where a.owner='OWNER' and a.table_name not in
    (select b.table_name from user_constraints b where b.table_name like '%BIN%') 
      and  a.constraint_type not in 'P')
    LOOP
      execute immediate 'alter table '||i.table_name||' disable constraint '||i.constraint_name||'';
    end loop;
    end;
    /
    
    truncate table TABLE_1;
    truncate table TABLE_2;
    
    
    begin
    for i in (select constraint_name, table_name from user_constraints a where a.owner='OWNER' and a.table_name not in
    (select b.table_name from user_constraints b where b.table_name like '%BIN%') 
      and  a.constraint_type not in 'P')
    LOOP
      execute immediate 'alter table '||i.table_name||' enable constraint '||i.constraint_name||'';
    end loop;
    end;
    /
    

    This script will first disable all the Constraints. Truncates the data in the tables and then enable the contraints.

    Hope it helps.

    cheers..

提交回复
热议问题