INSERT INTO...SELECT...
959944Oct 25 2012 — edited Oct 26 2012I've been trying to get the following piece of sql to work:
INSERT INTO inventory_part_char_tab
(part_no,contract,characteristic_code,unit_meas)
select distinct i.part_no, i.contract, 'PRTNO', i.unit_meas
from inventory_part_char_tab i
where not exists (select 1
from inventory_part_char_tab
where part_no = i.part_no and characteristic_code = 'PRTNO')
order by i.part_no
which returns the error: ORA-00001: unique contraint (XXXH1APP.INVENTORY_PART_CHAR_PK) violated
The file I'm trying to do this against is described as:
Name Type Nullable
PART_NO VARCHAR2(25)
CONTRACT VARCHAR2(5)
CHARACTERISTIC_CODE VARCHAR2(5)
UNIT_MEAS VARCHAR2(10) Y
ATTR_VALUE VARCHAR2(60) Y
ROWVERSION DATE Y
ROWTYPE VARCHAR2(30) Y
So, I'm assuming that I can't do this because I'm adding a duplicate record. But, when I just run the
select distinct i.part_no, i.contract, 'PRTNO', i.unit_meas
from inventory_part_char_tab i
where not exists (select 1
from inventory_part_char_tab
where part_no = i.part_no and characteristic_code = 'PRTNO')
order by i.part_no
portion of this statement, I don't get any duplicates. So, I'm kind of at a loss as to why I'm getting this constraint error.
Any ideas?
Michael