title: 00001. 00000 - "unique constraint (%s.%s) violated"
body: <p>I have MAIN_TABLE, which holds 7 million records. I have to</p>
  
  <ol>
  <li>keep last 3 months data In MAIN_TABLE</li>
  <li>archive last 4 to 12 months data in  MAIN_TABLE_ARCHIVAL</li>
  <li>purge all data older than 12 months</li>
  </ol>
  
  <p>I created a stored procedure with a cursor to copy from MAIN_TABLE to MAIN_TABLE_ARCHIVAL. 
  I have composite primary key(CONSTRAINT "PK_MAIN_TABLE" PRIMARY KEY ("SERVICE", "TR_SOURCE", "TR_ID")</p>
  
  <p>While copying I am getting  00001. 00000 -  "unique constraint (%s.%s) violated" error even though i am not inserting any duplicate key but at the same time records are copied into MAIN_TABLE_ARCHIVE.</p>
  
  <p>My code would look like (I have around 20 fields so I'm not pasting the whole code):</p>
  
  <pre><code>DECLARE
     c_id customers.id%type;
     c_name customers.name%type;
     c_addr customers.address%type;
  
     CURSOR c_customers is
      SELECT id, name, address FROM customers;
  BEGIN
    OPEN c_customers;
    LOOP
      FETCH c_customers into 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;
  /
  </code></pre>
  
  <p>I tried to debug, but no luck as I am new to PL/SQL. Can any one please tell me why it is happening? How should I implement the above assignment?</p>