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 -> PL/SQL: Subqueries in triggers...

PL/SQL: Subqueries in triggers...

From: Carsten Alexander <acamat_at_web.de>
Date: Fri, 1 Nov 2002 14:28:12 -0000
Message-ID: <aptvhs$50fpg$1@ID-86275.news.dfncis.de>


Hi there,

who can I use subqueries in triggers? First I tried...

> CREATE OR REPLACE TRIGGER TGR_CHK_ENT_KWD_ID_Type
> BEFORE
> INSERT OR UPDATE OF ENT_KWD_ID_Type ON tEntity
> FOR EACH ROW
> BEGIN
> IF :NEW.ENT_KWD_ID_Type NOT IN
> (SELECT KWD_ID FROM tKeyword WHERE UPPER(KWD_Section)='ENTITYTYPE')
> THEN
> RAISE_APPLICATION_ERROR
> (-20000,'Invalid KWD_ID for ENT_KWD_ID_Type!');
> END IF;
> END;
This does not work (PLS-00405: subquery not allowed in this context!). I tried something else by declaring a cursor...

> CREATE OR REPLACE TRIGGER TGR_CHK_ENT_KWD_ID_Type
> BEFORE
> INSERT OR UPDATE OF ENT_KWD_ID_Type ON tEntity
> FOR EACH ROW
> BEGIN
> CURSOR CRS_KWD_Section IS
> SELECT UPPER(KWD_Section)
> FROM tKeyword
> WHERE KWD_ID = :NEW.ENT_KWD_ID_Type;
> IF CRS_KWD_Section != 'ENTITYTYPE' THEN
> RAISE_APPLICATION_ERROR
> (-20000,'Invalid KWD_ID for ENT_KWD_ID_Type!');
> END IF;
> END;
This does not work either (PLS-00103: Encountered the symbol "CRS_KWD_SECTION"...). I have been working serveral hours now to check alternatives but according to my limited experience with PL/SQL I can't fix it.

Can someone help me out?

--
Thanks,
Carsten

P.S.: I've been using a check constraint on ENT_KWD_ID_Type so far, but
according to enhancements in the database model (it's still in development) I
always forget to recompile the constraint, of cause. This "dynamic" approach
would be much more comfortable. ;)
Received on Fri Nov 01 2002 - 08:28:12 CST

Original text of this message

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