Oracle Warning: Trigger Created With Compilation Errors
1002068Apr 10 2013 — edited Apr 10 2013I Can't seem to find what is wrong with this code. I have searched through it numerous times and cannot correct/find the error.
/* Trigger AskingPriceInitialValue */
CREATE OR REPLACE TRIGGER TRANS_AskingPriceIniValue
AFTER INSERT ON Transactions
FOR EACH ROW
DECLARE
rowcount INTEGER;
NetProfit NUMBER(10,2);
avgNetProfit NUMBER(10,2);
pragma autonomous_transaction;
BEGIN
SELECT Count(*) INTO rowcount
FROM Transactions T
WHERE T.WorkID = :new.WorkID;
IF rowcount = 1 THEN
UPDATE TRANSACTIONS
SET T.SalesPrice = 2 * T.AcquisitionPrice
WHERE T.TransactionID = :new.TransactionID;
ELSIF rowcount > 1 THEN
SELECT Sum(NetProfit) INTO NetProfit
FROM ArtistWorkNetView AW
WHERE AW.WorkID = :new.WorkID
GROUP BY AW.WorkID;
avgNetProfit := NetProfit / (rowcount - 1);
IF (avgNetProfit + :new.AcquisitionPrice) > (2 * :new.AcquisitionPrice) THEN
UPDATE TRANSACTIONS
SET T.AskingPrice = (avgNetProfit + :new.AcquisitionPrice)
WHERE T.TransactionID = :new.TransactionID;
ELSE
UPDATE TRANSACTIONS
SET T.AskingPrice = 2 * :new.AcquisitionPrice
WHERE T.TransactionID = :new.TransactionID;
END IF;
ELSE
dbms_output.put_line('ERROR');
END IF;
END;
/