Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Trigger to Prevent Duplicates

Re: Trigger to Prevent Duplicates

From: DStevens <dstevens_at_navidec.com>
Date: Mon, 18 Mar 2002 15:23:02 -0700
Message-ID: <a75pbs$bj5$1@newsreader.mailgate.org>


Solution 1: (Oracle 8i and above)
1) Create a function that is an autonomous transaction (to avoid mutating table error). This function will read the table to see if a duplicate exists. Return boolean.
2) Create a BEFORE INSERT/UPDATE trigger that calls this function. If duplicate, then raise an error, will cause the transaction to be rejected.

Simple Unique constraint will not work because some products allow duplication that day.

Another (Less clear) solution would be to create a unique constraint on customer/product/sequence. Increment sequence in the trigger for products that allow duplicates, don't increment for those that don't.

>
Received on Mon Mar 18 2002 - 16:23:02 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US