How can I implement this in the database?

0

Good, this is what he asks me for a table emple-depart-presupuesto

We must ensure that the spending on salaries of a department does not exceed 50% of the current budget.

CREATE OR REPLACE TRIGGER SALARIO50
BEFORE INSERT OR UPDATE ON emple
FOR EACH ROW
DECLARE 
    V_SALARIO NUMBER(4);
    V_PRESUPUESTO NUMBER(4);
BEGIN
SELECT SUM(SALARIO) INTO V_SALARIO
 FROM emple 
 GROUP BY DEPT_No;
 SELECT CANTIDAD INTO V_PRESUPUESTO
 FROM PRESUPUESTO
 WHERE DEPT_NO=:NEW.DEPT_NO;
  IF V_SALARIO>V_PRESUPUESTO/2 THEN 
    RAISE_APPLICATION_ERROR (-20234, 'Has exedido del 50% del presupuesto de deste departamento');
END;

And the error he gives me is this:

LINE/COL ERROR
-------- -----------------------------------------------------------------
13/4     PLS-00103: Se ha encontrado el símbolo ";" cuando se esperaba uno
         de los siguientes:
         if
    
asked by user7407723 14.06.2017 в 00:11
source

1 answer

2

The error is on line 13 at position 4, that is on the line:

END;

And it is because the IF THEN % is used to finish the block END IF in PL / SQL. Just add IF :

END IF;
    
answered by 14.06.2017 в 00:27