oracle - Need to save data before delete and re-insert -


i have change existing table follows.

  1. drop existing primary key
  2. add new primary key

in regard, have delete existing data before creating new primary key. need re-insert data. table existing in multiple schemas , need query or pl/sql block perform function.

i used following queries:

alter table schema1.a drop constraint pk_a;  alter table schema1.a add pid varchar2(40 char);  alter table schema1.a add (constraint pk_a primary key (pid));  

it failing @ last query with

ora-01449: column contains null values; cannot alter not null 

i don't think there way drop table or object among multiple schemas single drop statement. can use below mentioned pl/sql careful in using , possible include clause possible.

set serveroutput on;    declare                cursor c            select username dba_users;    table_check_cnt number;     dropsql         varchar2(300);  begin     dbms_output.put_line('execution of block starts');      c1 in c      loop        select count(*)        table_check_cnt        dba_tables        owner       =c1.username        , table_name    ='foo';         if table_check_cnt=1          dbms_output.put_line('count '||table_check_cnt);          dropsql := 'drop table '|| c1.username || '.foo';          execute immediate dropsql;        end if;      end loop;    end;    

and ora-01449 error there null record present on field on creating primary constraint remove null value every record in field , should unique also.


Comments