hey I want to prevent insert new record if the total salary is greater than 1000 , so I tried to solve this issue by using trigger 

```
CREATE OR REPLACE TRIGGER totalsal
    BEFORE INSERT OR UPDATE
    ON saltable
    FOR EACH ROW
DECLARE
    CURSOR sumsalary  IS
        SELECT SUM(sal) AS sum_salary FROM saltable;

    total                                   NUMBER;
BEGIN
    OPEN sumsalary;

    FETCH sumsalary INTO total;

    DBMS_OUTPUT.PUT_LINE('value is  ');
    DBMS_OUTPUT.PUT_LINE(total);

    CLOSE sumsalary;

    IF (total < 1000)
    THEN
        DBMS_OUTPUT.PUT_LINE('in range');
        :new.sal    := :new.sal;
    ELSE
        DBMS_OUTPUT.PUT_LINE('exceed limit');
    END IF;
END;
/

```

as you can see here I used cursor to get the sum then fetch value and if condition for comparison but its not working perfectly! it insert new record even if sum salary exceed range 

anyone knows how to solve such a problem.