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: Conditional Trigger

Re: Conditional Trigger

From: <fitzjarrell_at_cox.net>
Date: Tue, 20 Nov 2007 07:42:44 -0800 (PST)
Message-ID: <95bde827-319d-4e34-89c3-af8d1eefa075@41g2000hsh.googlegroups.com>


On Nov 20, 9:27 am, mowi..._at_hotmail.com wrote:
> Daniel and David, thanks.
>
> In deed, Daniel, they are four and not three as stated above, and I am
> sorry that I left some more details out when I wrote the first time.
> It's like this:
>
> For a new article to be added to the table with a ISBN that already
> exists in the in that field, it must exist in the PERIODICAL_OWNER
> field. The logic behind this is that instead of enforcing a UNIQUE
> constraint on ISBN a trigger is used to prevent unnecessary duplicates
> in ISBN. The reason for avoinding the unique constraint is that one or
> more articles may come in with the same ISBN in different periodicals.
> In this case, therefore, the PERIODICAL#_OWNER must be included and it
> refers to the the original PERIODICAL#.
>
> PERIODICAL# (NUMBER 9).
> ISBN (NUMBER 9),
> TITLE (VARCHAR2 500)
> PERIODICAL_OWNER (NUMBER 9)
>
> I did modify the trigger thus:
>
> CREATE OR REPLACE TRIGGER ibr_prdc
> BEFORE INSERT ON PERIODICAL FOR EACH ROW
> DECLARE
> ISBNo PERIODICAL.ISBN%TYPE;
> tnr PERIODICAL.PERIODICAL#%TYPE;
> tnre PERIODICAL.PERIODICAL#_OWNER%TYPE;
> BEGIN
> Select ISBN, PERIODICAL#,PERIODICAL#_OWNER into ISBNo,tnr,tnre
> FROM PERIODICAL Where ISBNo =:New.ISBN And tnre = :New.PERIODICAL#;
> IF ISBNo = :New.ISBN And
> tnre <>:New.PERIODICAL# THEN
> RAISE_APPLICATION_ERROR(-20070, 'ERROR>>' ||
> ' PERIODICAL:' ||
> ' For ISBN that already exists in the basen, it' ||
> ' must exist in periodicald to be accepted.');
> ELSE
> :New.ISBN := :New.ISBN;
> END IF;
>
> Daniel, when I use BEFORE INSERT I get:
> ORA-01403: no data was found
> ...
>
> When I use AFTER INSERT I get:
> ORA-04091: The table PERIODICAL is muteting, ...
>
> The trigger is not reporting any errors when compiled.
> ..
>
> Thank you guys for the help:)
>
> --
> Me

Daniel didn't explain that, I did. You need to get a count(*) of the records currently in the table and process based upon that result. Presuming the count(*) is 0 then you should be bypassing all of the conditional logic in the trigger. This will 'fix' your 'no data found' issue.

David Fitzjarrell Received on Tue Nov 20 2007 - 09:42:44 CST

Original text of this message

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