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 -> Help, please. Trouble with validate trigger...

Help, please. Trouble with validate trigger...

From: Rob <crwng_at_comcast.net>
Date: 9 Jun 2004 06:46:24 -0700
Message-ID: <fd856ad0.0406090546.46f9b072@posting.google.com>


I'm trying to implement the following trigger on an Oracle 9i database (running on Solaris 8) with three tables. The tables are

LR_READER
LR_ATTRIBUTE
LR_READERATTRIBUTE

I get an error whenever I try to insert/update/delete the ATTRIBUTEID foreign key in LR_READERATTRIBUTE. The error says: "ORA-04098: trigger 'SCOTTFORESMAN.VALIDATEFK_5B512FC0' is invalid and failed re-validation"

Full source code is included at the bottom of the message for context, but this snippet just below is the one that appears to be throwing the error.

--Before Update/Insert Validate Foreign Key.
create trigger VALIDATEFK_5B512FC0
before insert or update on LR_READERATTRIBUTE referencing OLD as old NEW as new
for each row when (

        new.ATTRIBUTEID IS NOT NULL )
declare

	pk_not_found EXCEPTION;
	mutating_table EXCEPTION;
	PRAGMA EXCEPTION_INIT (mutating_table,-4091);
	parent_row LR_ATTRIBUTE%ROWTYPE;
	cursor c1 (fkVal1 NUMBERPS) is
		SELECT *
		FROM LR_ATTRIBUTE WHERE
			ID = fkVal1
		for update of
			ID;
begin
	open c1(:new.ATTRIBUTEID);
	fetch c1 into parent_row;
	if c1%NOTFOUND then
		raise pk_not_found;
	end if;
	close c1;
exception
	when pk_not_found then
		close c1;
		raise_application_error(-20000,'Invalid FK value');
	when mutating_table then
		NULL;
	when others then
		close c1;
		raise;

end;

FULL SOURCE CODE

create sequence LR_ATTRIBUTE_SEQ;

CREATE OR REPLACE TRIGGER ID_TRIG_ATTRIBUTE BEFORE INSERT
ON LR_ATTRIBUTE
FOR EACH ROW
BEGIN
SELECT LR_ATTRIBUTE_SEQ.NEXTVAL
INTO :NEW.ID
FROM DUAL;
END;
/

create sequence LR_READERATTRIBUTE_SEQ;

CREATE OR REPLACE TRIGGER ID_TRIG_READERATTRIBUTE BEFORE INSERT
ON LR_READERATTRIBUTE
FOR EACH ROW
BEGIN
SELECT LR_READERATTRIBUTE_SEQ.NEXTVAL
INTO :NEW.ID
FROM DUAL;
END;
/

alter table LR_READERATTRIBUTE
	add constraint READERREADERATTRIBUTE foreign key (
		ISBN)
	 references LR_READER (
		ISBN) DISABLE; 

--Before Update/Insert Validate Foreign Key.
create trigger VALIDATEFK_5B512FC0
before insert or update on LR_READERATTRIBUTE referencing OLD as old NEW as new
for each row when (

        new.ATTRIBUTEID IS NOT NULL )
declare

	pk_not_found EXCEPTION;
	mutating_table EXCEPTION;
	PRAGMA EXCEPTION_INIT (mutating_table,-4091);
	parent_row LR_ATTRIBUTE%ROWTYPE;
	cursor c1 (fkVal1 NUMBERPS) is
		SELECT *
		FROM LR_ATTRIBUTE WHERE
			ID = fkVal1
		for update of
			ID;
begin
	open c1(:new.ATTRIBUTEID);
	fetch c1 into parent_row;
	if c1%NOTFOUND then
		raise pk_not_found;
	end if;
	close c1;
exception
	when pk_not_found then
		close c1;
		raise_application_error(-20000,'Invalid FK value');
	when mutating_table then
		NULL;
	when others then
		close c1;
		raise;

end;

--Before Update/Insert Validate Foreign Key.
create trigger VALIDATEFK_2AA438F2
before insert or update on LR_READERATTRIBUTE referencing OLD as old NEW as new
for each row when (

        new.ISBN IS NOT NULL )
declare

	pk_not_found EXCEPTION;
	mutating_table EXCEPTION;
	PRAGMA EXCEPTION_INIT (mutating_table,-4091);
	parent_row LR_READER%ROWTYPE;
	cursor c1 (fkVal1 CHAR) is
		SELECT *
		FROM LR_READER WHERE
			ISBN = fkVal1
		for update of
			ISBN;
begin
	open c1(:new.ISBN);
	fetch c1 into parent_row;
	if c1%NOTFOUND then
		raise pk_not_found;
	end if;
	close c1;
exception
	when pk_not_found then
		close c1;
		raise_application_error(-20000,'Invalid FK value');
	when mutating_table then
		NULL;
	when others then
		close c1;
		raise;

end; Received on Wed Jun 09 2004 - 08:46:24 CDT

Original text of this message

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