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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: TRIGGERS

Re: TRIGGERS

From: david wendelken <davewendelken_at_earthlink.net>
Date: Wed, 18 May 2005 09:47:22 -0700 (PDT)
Message-ID: <3770844.1116434842529.JavaMail.root@bert.psp.pas.earthlink.net>


I don't think you should be getting a unique key error with the pre-insert row trigger you are showing. I think you should be getting a totally different error.

Please show the entire create trigger statement, not just the pl/sql code in it.

-----Original Message-----
From: Kean Jacinta <jacintakean_at_yahoo.com> Sent: May 18, 2005 9:33 AM
To: oracle-l_at_freelists.org
Subject: Re: TRIGGERS

HI,

here is what i have written in trigger body, i am really stuck here. help me up , it;s still not working . System still complain about the unique key error. **:(

DECLARE
  REFCOUNT NUMBER;
  DUP_VAL_ON_INDEX EXCEPTION;

  TEMP                NUMBER;
 

BEGIN
   IF INSERTING THEN

      
   LOOP      
      SELECT COUNT(*) INTO REFCOUNT
      FROM myclass
      WHERE :NEW.id = id;
                  
      IF REFCOUNT > 0 THEN --RECORD EXISTED IN
DATABASE
      SELECT myclass_seq.NEXTVAL INTO TEMP FROM DUAL;
      END IF;
             
      
  END LOOP;    
      
      IF :NEW.ID IS NULL THEN
      
            
      SELECT myclass_SEQ.NEXTVAL 
      INTO :NEW.ID 
      FROM DUAL;
      END IF;
         

   END IF; --MAIN IF END; Note : have no idea how to use the exception handler

JKean

> If you really want to handle that, you have three
> choices:
>
> 1) Live with it. If you have a program that
> assigns the id values for you, it should be getting
> its next value from the sequence also. If you do
> that, this just isn't a problem in real life. If
> you aren't willing to ALWAYS get the next id value
> from a sequence, you probably shouldn't be using a
> sequence at all.
>
> 2) Relatively simple, partial solution. Use a
> pre-statement trigger on insert, have it grab the
> next sequence value and verify that the record for
> that sequence number is not already in the table.
> If it is, get the next sequence value until you find
> an empty one. Assume that all the ones after that
> are ok from then on. Ignore the fact taht you throw
> away a sequence number each time you do a statement.
> Remember, I said *partial* solution.
>
> 3) Read up on mutating table errors and autonomous
> transactions. This will take you awhile to read and
> experiment with. We have time to help with specific
> problems, but not to write it for you.
> Ask again after you've read that material and are
> are stuck.
>
>
>
> -----Original Message-----
> From: Kean Jacinta <jacintakean_at_yahoo.com>
> Sent: May 18, 2005 8:02 AM
> To: david wendelken <davewendelken_at_earthlink.net>
> Subject: Re: TRIGGERS
>
> david,
>
> :P oh i see . I am so blur. My concern,
>
> ID
> ---
> 1 <-- autogenerated
> 2 <-- autogenerated
> 3 <-- autogenerated
> 4 <-- manually created
> 5 <-- manually created
>
> My current sequence stay at : 3 , if i issued an
> autotgenerated insert again it will surely prompt
> unique id alrdy existed... or some sort of database
> error. How can then trigger being smart enough to
> silently generate autoid 6 without raising error ?
>
> I am very close to my objectives alrdy :P
>
> Thank in advance
> Jkean
>
                



Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail
--
http://www.freelists.org/webpage/oracle-l

--
http://www.freelists.org/webpage/oracle-l
Received on Wed May 18 2005 - 12:53:26 CDT

Original text of this message

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