Oracle Trigger with If Statement

Viewed 22

I'm trying to get an oracle trigger to work.

Here's the code I have so far:

CREATE OR REPLACE trigger Atualizar_Saldo 
AFTER INSERT ON movimento
FOR EACH ROW
DECLARE 
tipo     CHAR(1);
saldo  NUMBER(20, 4);
valor    NUMBER(20, 4);

BEGIN

IF(:new.tipo = 1) THEN

    UPDATE conta set saldo = saldo + :new.valor where numero = :new.numero;

ELSIF(:new.tipo = 0) THEN
    update conta set saldo = saldo - :new.valor where numero = :new.numero;

END IF;
END;

The problem that I'm facing at the moment is with the if statement, when i try to add another condition it doesn`t work

ELSIF(:new.tipo = 0 and :new.valor < saldo ) THEN
    update conta set saldo = saldo - :new.valor where numero = :new.numero;

Is there anyway I can fix this?

Thanks in advance

0 Answers
Related