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

Member Avatar
hfx642

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.