Click here to Skip to main content
15,889,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CREATE OR REPLACE TRIGGER MOA_patcharges_balance
BEFORE INSERT ON patcharges
FOR EACH ROW
DECLARE
v_outstanding number;
both_null EXCEPTION;
both_not_null EXCEPTION;
BEGIN
SELECT Moa_patcharges.outstanding INTO v_outstanding
FROM Moa_patcharges
WHERE Moa_patcharges.patID= :new.patID AND
entryDate = (SELECT MAX(entryDate) FROM Moa_patcharges
WHERE Moa_patcharges.patID= :new.patID);
IF (:new.payments IS NOT NULL AND :new.charges IS NOT NULL)
THEN RAISE both_not_null;
END IF;
IF (:new.payments IS NULL AND :new.charges IS NULL)
THEN RAISE both_null;
END IF;
IF (:new.charges IS NOT NULL AND :new.payments IS NULL)
THEN RAISE charge_not_null;
END IF;
IF (:new.payments IS NOT NULL AND :new.charges IS NULL)
THEN RAISE payments_not_null;
END IF;
EXCEPTION
WHEN charges_not_null THEN
:new.outstanding := v_outstanding + :new.charges;
dbms_output.put_line ('This is the new balance' || TO_CHAR(:new.outstanding));
WHEN payments_not_null THEN
:new.outstanding := v_outstanding - :new.payments;
dbms_output.put_line('This is the new balance' || TO_CHAR(:new.outstanding));
WHEN both_null THEN
RAISE_APPLICATION_ERROR (-20325, May not add a record with both payment and charge information.');
WHEN both null THEN
RAISE_APPLICATION_ERROR (-20325, 'May not add a record with both payment and charge information.');
END;
/

What I have tried:

EXCEPTION
WHEN charges_not_null THEN
:new.outstanding := v_outstanding + :new.charges;
dbms_output.put_line ('This is the new balance' || TO_CHAR(:new.outstanding));
WHEN payments_not_null THEN
:new.outstanding := v_outstanding - :new.payments;
dbms_output.put_line('This is the new balance' || TO_CHAR(:new.outstanding));
WHEN both_null THEN
Posted
Updated 16-Apr-18 21:06pm
Comments
_Asif_ 17-Apr-18 3:04am    
It seems that you have missed a single quotation here "RAISE_APPLICATION_ERROR (-20325, 'May not add a record with both payment and charge information.')"

1 solution

See the line
SQL
RAISE_APPLICATION_ERROR (-20325, May not add a record with both payment and charge information.');
The quote character at the begin of the message string is missing.

Would have been obvious when formatting code as such in the question or using an editor with syntax highlighting:
SQL
RAISE_APPLICATION_ERROR (-20325, 'May not add a record with both payment and charge information.');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900