Reputation: 375
My goal is to create a trigger that checks if the number you are trying to enter NR_RECIBO
is in the table Doc_cabecalho
with the attribute TIPO_DOC = 4
CREATE OR REPLACE TRIGGER ValidaRecibo
BEFORE INSERT ON Recibo
FOR EACH ROW
DECLARE val NUMBER;
BEGIN
SELECT COUNT(*) INTO val
FROM Doc_cabecalho
WHERE (TIPO_DOC = 4 AND NR_DOCUMENTO = :NEW.NR_RECIBO);
IF val = 0
THEN (-20502, ' Only from department 4 ');
END IF;
END ValidaRecibo;
Yet, this raises the following error:
PLS-00103: Encountered the symbol "," when expecting one of the following:
* & = - + < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like like2 like4 likec as between || member submultiset
Upvotes: 2
Views: 93
Reputation: 1948
IF val = 0 THEN raise_application_error(-20502, ' Only from department 6 ');
And you should decide between DOC_TIPO and TIPO_DOC ;)
Upvotes: 1