2

My update receives the following error when updating to the database:

ORA-00001: unique constraint (DONALDBURY.BARS_ID_PK) violated

I am using the following code as my update. I am not wanting to get rid of the constraint but to find out a workaround for it. I want to stop the duplicates values being set.

MERGE INTO bars DEST_TABLE
USING (select :P3_filename as filename from dual) SOURCE_TABLE
ON (DEST_TABLE.name = SOURCE_TABLE.filename)
WHEN MATCHED THEN 
 UPDATE SET  image = ORDSYS.ORDImage()
WHEN NOT MATCHED THEN 
INSERT (
      image_id,
      filename,
      image,
      name,
      address,
      postcode,
      description)
      VALUES (:P3_image_id,
     :P3_filename,
      ORDSYS.ORDImage(),
     :P3_NAME,
     :P3_ADDRESS,
     :P3_POSTCODE,
     :P3_DESCRIPTION);

3 Answers3

0

There is an unique constraint named BARS_ID_PK on image_id column - this constraint prohibits multiple rows from having the same value in this columns.

You are trying to insert a new row with image_id that already exists in the table.

To avoid this error, simply assing to :P3_image_id placeholder in the query a value, that doesn't exists yet in the table.

krokodilko
  • 35,300
  • 7
  • 55
  • 79
0

Per the information provided, there is a primary key on the DEST table based on IMAGE_ID so duplicate IMAGE_IDs are not allowed. The MERGE statement checks for the existence of record based on filename (DEST_TABLE.filename). You would need to check on the image_id instead (or both filename and image_id). Based on the information provided, it seems that there may be multiple image_ids with the same file name in your bars table.

vmachan
  • 1,672
  • 1
  • 10
  • 10
-1

As a work around... I believe the Image ID is a numeric columns.. Find out the Max Image id from the table. Add MaxImageID+1 while inserting in to the table... This values will always be unique and hopefully resolve your issue.. Cheers..!!

Indiecoder
  • 186
  • 3
  • 17