oracle - 00001. 00000 - "unique constraint (%s.%s) violated" -


i have main_table, holds 7 million records. have to

  1. keep last 3 months data in main_table
  2. archive last 4 12 months data in main_table_archival
  3. purge data older 12 months

i created stored procedure cursor copy main_table main_table_archival. have composite primary key(constraint "pk_main_table" primary key ("service", "tr_source", "tr_id")

while copying getting 00001. 00000 - "unique constraint (%s.%s) violated" error though not inserting duplicate key @ same time records copied main_table_archive.

my code (i have around 20 fields i'm not pasting whole code):

declare    c_id customers.id%type;    c_name customers.name%type;    c_addr customers.address%type;     cursor c_customers     select id, name, address customers; begin   open c_customers;   loop     fetch c_customers c_id, c_name, c_addr;     exit when c_customers%notfound;     dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);     commit;   end loop;   close c_customers; end; / 

i tried debug, no luck new pl/sql. can 1 please tell me why happening? how should implement above assignment?

to copy data 1 table don't need cursor. don't need stored procedures. make 1 simple sql-statement:

insert main_table_archival select * main_table <...your condition...> 

to improve perfomance use "+append" hint.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -