lunes, 23 de mayo de 2011

Create or Replace Trigger Transaccion
Before insert on Giro
For each row
DECLARE

Vsaldo cuenta.saldo%type;
Vlimite lineacredito.saldo%type;
Descuento lineacredito.saldo%type;
line lineacredito.saldo%type;

Begin

Select saldo into Vsaldo
From Cuenta
Where IdCuenta= :new.IdCuenta;

Select saldo into Vlimite
From LineaCredito
Where IdCuenta= :new.IdCuenta;




if Vsaldo+Vlimite >= :new.monto then
Descuento := :new.monto - Vsaldo;


Update Cuenta
Set Saldo = Saldo-:new.Monto
where Idcuenta= :new.IdCuenta;

Update LineaCredito
Set Saldo = Saldo - Descuento
where Idcuenta = :new.IdCuenta;

Select IdLinea into line
From LineaCredito
Where IdCuenta= :new.IdCuenta;


insert into UsoLinea values (id_uso.nextval,line,sysdate,Descuento);

Else
dbms_output.put_line('No Alcanza el Saldo Disponible');
End if;
End Transaccion;


CREATE SEQUENCE id_uso
INCREMENT BY 1
START WITH 1



ALTER TABLE algo DROP COLUMN nombre

No hay comentarios.:

Publicar un comentario