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

Home -> Community -> Usenet -> c.d.o.server -> Re: cancel an insert within the trigger?

Re: cancel an insert within the trigger?

From: Ben Graham <bengraham_at_xsmail.com>
Date: 21 Sep 2004 08:21:13 -0700
Message-ID: <f858471c.0409210721.3a828218@posting.google.com>


avanrossem_at_hotmail.com (Andre) wrote in message news:<4d32d1be.0409210219.26642641_at_posting.google.com>...
> Hello all,
>
> I have created an insert trigger:
> If I do a count on the table and this count results in a 1 or higher I
> would not insert the record. (of_id is not the primary key)
>
> CREATE OR REPLACE TRIGGER iu_cli BEFORE insert or update on client
> FOR EACH ROW
> BEGIN
> CC number;
> IF INSERTING
> THEN
> select count(*) into CC from client WHERE of_id = :new.of_id;
> If CC > 1 then
> --do not insert?
> ????????????
> end if;
> END IF;
> END;
> /
>
>
> The Question is: Can I do this this way?
> What code to put on the ???? marks?
>
> Thanks All,
> Anneke

CREATE OR REPLACE TRIGGER iu_cli BEFORE insert or update on client FOR EACH ROW
DECLARE
CC number;
BEGIN
   IF INSERTING
   THEN
    select count(*) into CC from client WHERE of_id = :new.of_id;     If CC > 0 then

      --do not insert
       raise_application_error(-20000,'Invalid of_id. Your message here');
    end if;
   END IF;
END;
/

...or create an unique constraint on client.of_id:

alter table client
add constraint client_of_id_uni
unique (of_id); Received on Tue Sep 21 2004 - 10:21:13 CDT

Original text of this message

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