i would like to create a simple trigger to check a stored variable from a table.
if the value of the variable is ‘1’, then approve the insertion
else if the value of the variable is ‘2’, then prompt error message.
CREATE OR REPLACE TRIGGER approval
BEFORE INSERT ON VIP
REFERENCING OLD AS MEMBER
FOR EACH ROW
DECLARE
CONDITION_CHECK NUMBER;
BEGIN
SELECT CONDITION INTO CONDITION_CHECK FROM MEMBER;
IF CONDITION_CHECK = '2' THEN
RAISE_APPLICATION_ERROR (-20000, ' UPGRADE DENIED!');
END IF;
END;
But this trigger disable all the entries even when the condition value is ‘1’.
Use
AFTERtriggers to check conditions: the values can be modified by otherBEFOREtriggers. InAFTERtriggers, you are guaranteed that the value won’t be changed afterwards.It seems you’re missing a condition in your
SELECT(if as I believe you’re trying to get the value from another table):