0

Hey everyone,

Is this the right way how to make a trigger in Oracle?

CREATE OR REPLACE TRIGGER "TRI_AMOUNT_REDUCTION"
	      BEFORE INSERT ON "PURCHASE"
	      FOR EACH ROW
	    BEGIN
		IF (:NEW.CLIENTNO =SELECT C.CNAME, T.CLIENTNO, T.TOTAL FROM

                       CLIENT C, ( SELECT A.* FROM (SELECT CLIENTNO, SUM(AMOUNT)  AS 

TOTAL FROM PURCHASE GROUP BY CLIENTNO) A,(SELECT MAX(B.TOTAL) AS TOP FROM(SELECT 

CLIENTNO, SUM(AMOUNT) AS TOTAL FROM PURCHASE GROUP BY CLIENTNO)B)C 

WHERE A.TOTAL=C.TOP) T
WHERE C.CLIENTNO = T.CLIENTNO; ) THEN
			:NEW.AMOUNT := AMOUNT - (AMOUNT * 0.1);
		END IF;
	    END;
	    /

When I run this script, the server says "the trigger created with compilation errors"... I don't know what that exactly means

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by hfx642
0

It means that this is NOT the correct way to create a trigger!!
You're making it too complicated. Simplify it.
Hint: A trigger is a PL/SQL block. Write your trigger as such.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.