954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Triggers

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

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

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.

hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 248
Solved Threads: 105
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You