I am creating insert statements to populate my tables. They run fine when I test them, however, when I start to spool the same code that worked previously suddenly gives me an error (ORA-00001: unique constraint violated). When researching the issue it seems that the issue occurs when trying to enter duplicate information into a table. However, I always clear the sequences and re-enter them before spooling so this wouldn't make sense. Here is an example of what I'm trying to run, and as I said the code works fine otherwise:
SQL> INSERT INTO bill_tos_sr
2 (
3 bill_to_no,
4 bill_to_name,
5 bill_to_street,
6 bill_to_city,
7 bill_to_state,
8 bill_to_zip,
9 bill_to_phone
10 )
11 VALUES
12 (bill_tos_seq.NEXTVAL,
13 'Walmart',
14 '1000 Indiantown St',
15 'Ft Lauderdale',
16 'FL',
17 '33401',
18 '9438476698'
19 );
INSERT INTO bill_tos_sr
*
ERROR at line 1:
ORA-00001: unique constraint (MONPM16.BILL_TO_NO_PK) violated
I'll assume
BILL_TO_NO_PK
is the PK/unique constraint of the columnBILL_TO_NO
.When inserting, you are are providing new values from the sequence
bill_tos_seq.NEXTVAL
. It seems the sequence was restarted, or that data was entered manually in the table.In any case, the sequence values are colliding with existing data in the table.
Solution? I would find the max value for the column, and then set the sequence value to one more than that value.