You are on page 1of 12

__________________________________________________________________

SECUENCIA PARA HACER LAS LLAVES FORANEAS


AUTOINCREMENTABLES
__________________________________________________________________
create sequence codigos
start with 1
increment by 1
maxvalue 99999
minvalue 1;
__________________________________________________________________
TRIGGERS QUE SE EJECUTAN ANTES DE HACER UN INSERT A CADA TABLAS
__________________________________________________________________
create trigger reg_auditoria before insert on auditoria
for each row
begin select codigos.nextval into :new.no_auditoria from
dual;
end;

create trigger reg_cheque before insert on cheque


for each row
begin select codigos.nextval into :new.no_cheque from
dual;
end;

create trigger reg_chequera before insert on chequera


for each row
begin select codigos.nextval into :new.no_chequera from
dual;
end;

create trigger reg_cliente before insert on cliente


for each row
begin select codigos.nextval into :new.cod_cliente from
dual;
end;

create or replace trigger reg_cuenta before insert on cuenta


for each row
begin select codigos.nextval into :new.no_cuenta from
dual;
end;

create trigger reg_cod_empleado BEFORE INSERT ON empleado


FOR EACH ROW
BEGIN SELECT codigos.NEXTVAL INTO :NEW.cod_empleado FROM
DUAL;
END;

create trigger reg_lote before insert on lote


for each row
begin select codigos.nextval into :new.no_lote from dual;
end;

create trigger reg_movimiento before insert on movimiento


for each row
begin select codigos.nextval into :new.no_movimiento from
dual;
end;

create trigger reg_cod_rol before insert on rol


for each row
begin select codigos.NEXTVAL into :new.cod_rol from dual;
end;

create trigger reg_sucursal before insert on sucursal


for each row
begin select codigos.nextval into :new.cod_sucursal from
dual;
end;

create trigger reg_tarjeta before insert on tarjeta


for each row
begin select codigos.nextval into :new.no_tarjeta from
dual;
end;

create trigger reg_tipo_cheque before insert on tipo_cheque


for each row
begin select codigos.nextval into :new.id_tipo_cheque from
dual;
end;

create trigger reg_tipo_tran before insert on tipo_transaccion


for each row
begin select codigos.nextval into :new.cod_t_tran from
dual;
end;

create trigger reg_cod_tran before insert on transaccion


for each row
begin select codigos.nextval into :new.no_transaccion from
dual;
end;

_________________________________________________________
PROCEDIMIENTO PARA CHEQUERA
_________________________________________________________
create procedure I_M_E_chequera(
no_chequera int,
no_cuenta int,
rango_inicial varchar,
rango_final varchar
)
is begin if inserting then
insert into chequera (no_cuenta, rango_inicial, rango_final)
values(no_cuenta, rango_inicial, rango_final);
else if deleting then
delete from chequera where no_chequera = no_chequera;
else if updating then
update chequera set no_cuenta = no_cuenta,
rango_inicial=rango_inicial,
rango_final=rango_final;
end if; end if; end if; end;

_________________________________________________________
Procedimiento para cheque
_________________________________________________________
create or replace procedure I_M_E_cheque(
no_cheque integer,
fecha_emitido date,
no_cuenta integer,
cod_sucursal integer,
monto varchar,
estado varchar,
no_lote integer
)
is begin if inserting then
insert into cheque(no_cheque, fecha_emitido, no_cuenta,
cod_sucursal, monto, estado, no_lote) values(no_cheque,
fecha_emitido, no_cuenta, cod_sucursal, monto, estado, no_lote);
else if deleting then
delete from cheque where no_cheque = no_cheque;
else if updating then
update cheque set no_cheque = no_cheque, fecha_emitido =
fecha_emitido, no_cuenta = no_cuenta, cod_sucursal = cod_sucursal,
monto = monto, estado = estado, no_lote = no_lote;
end if; end if; end if; end;

_________________________________________________________
______
PROCEDIMIENTO PARA CLIENTE
_________________________________________________________
______
create or replace procedure I_M_E_cliente(
cod_clie integer,
nombre_clie varchar,
apellido_clie varchar,
direccion_clie varchar,
telefono_clie varchar,
fecha_nac date,
estado_civil varchar,
dpi varchar
)
is begin if inserting then
insert into cliente(cod_clie, nombre_clie, apellido_clie,
direccion_clie, telefono_clie, fecha_nac, estado_civil, dpi)
values(cod_clie, nombre_clie, apellido_clie, direccion_clie,
telefono_clie, fecha_nac, estado_civil, dpi);
else if deleting then
delete from cliente where cod_clie = cod_clie;
else if updating then
update cliente set cod_clie = cod_clie, nombre_clie = nombre_clie,
apellido_clie = apellido_clie, direccion_clie = direccion_clie,
telefono_clie = telefono_clie, fecha_nac = fecha_nac, estado_civil
= estado_civil, dpi = dpi;
end if; end if; end if; end;

_________________________________________________________
______
PROCEDIMIENTO PARA CUENTA
_________________________________________________________
______
create or replace procedure I_M_E_cuenta(
no_cuenta integer,
cod_sucursal integer,
cod_clie integer,
nombre_cuenta varchar,
fecha_creacion date,
saldo varchar,
estado varchar,
saldo_flotante varchar
)
is begin if inserting then
insert into cuenta(no_cuenta, cod_sucursal, cod_clie,
nombre_cuenta, fecha_creacion, saldo, estado, saldo_flotante)
values(no_cuenta, cod_sucursal, cod_clie, nombre_cuenta,
fecha_creacion, saldo, estado, saldo_flotante);
else if deleting then
delete from cuenta where no_cuenta = no_cuenta;
else if updating then
update cuenta set no_cuenta = no_cuenta, cod_sucursal =
cod_sucursal, cod_clie = cod_clie, nombre_cuenta = nombre_cuenta,
fecha_creacion = fecha_creacion, saldo = saldo, estado = estado,
saldo_flotante = saldo_flotante;
end if; end if; end if; end;

_________________________________________________________
______
PROCEDIMIENTO PARA EMPLEADO
_________________________________________________________
______
create or replace procedure I_M_E_empleado(
cod_empleado integer,
nombre_emp varchar,
apellido_emp varchar,
direccion_emp varchar,
telefono_emp varchar,
dpi varchar,
fecha_nac date,
cod_rol integer,
nom_usuario varchar,
pass varchar
)
is begin if inserting then
insert into empleado (cod_empleado, nombre_emp, apellido_emp,
direccion_emp, telefono_emp, dpi, fecha_nac, cod_rol, nom_usuario,
pass) values(cod_empleado, nombre_emp, apellido_emp,
direccion_emp, telefono_emp, dpi, fecha_nac, cod_rol, nom_usuario,
pass);
else if deleting then
delete from empleado where cod_empleado = cod_empleado;
else if updating then
update empleado set cod_empleado = cod_empleado,
nombre_emp=nombre_emp, apellido_emp = apellido_emp, direccion_emp
= direccion_emp,
telefono_emp=telefono_emp, dpi = dpi, fecha_nac=fecha_nac, cod_rol
= cod_rol, nom_usuario=nom_usuario, pass=pass;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA LOTE
_________________________________________________________
create or replace procedure I_M_E_lote(
no_lote integer,
descripcion varchar
)
is begin if inserting then
insert into lote(no_lote, descripcion) values(no_lote,
descripcion);
else if deleting then
delete from lote where no_lote = no_lote;
else if updating then
update lote set no_lote = no_lote, descripcion = descripcion;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA ROL
_________________________________________________________
create procedure I_M_E_rol(
cod_rol integer,
nombre_rol varchar
)
is begin if inserting then
insert into rol (cod_rol, nombre_rol) values(cod_rol, nombre_rol);
else if deleting then
delete from rol where cod_rol = cod_rol;
else if updating then
update rol set cod_rol = cod_rol, nombre_rol=nombre_rol;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA SUCURSAL
_________________________________________________________
create or replace procedure I_M_E_sucursal(
cod_sucursal integer,
nombre_sucursal varchar,
pais varchar,
telefono varchar,
direccion varchar
)
is begin if inserting then
insert into sucursal(cod_sucursal, nombre_sucursal, pais,
telefono, direccion) values(cod_sucursal, nombre_sucursal, pais,
telefono, direccion);
else if deleting then
delete from sucursal where cod_sucursal = cod_sucursal;
else if updating then
update sucursal set cod_sucursal = cod_sucursal, nombre_sucursal =
nombre_sucursal, pais = pais, telefono = telefono, direccion =
direccion;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA TRANSACCION
_________________________________________________________
create procedure I_M_E_transaccion(
no_transaccion integer,
cod_t_trans integer,
no_cuenta integer,
cod_sucursal integer,
cod_empleado integer,
fecha_hora Date,
monto varchar
)
is begin if inserting then
insert into transaccion (no_transaccion, cod_t_trans, no_cuenta,
cod_sucursal, cod_empleado, fecha_hora, monto)
values(no_transaccion, cod_t_trans, no_cuenta, cod_sucursal,
cod_empleado, fecha_hora, monto);
else if deleting then
delete from transaccion where no_transaccion = no_transaccion;
else if updating then
update transaccion set no_transaccion = no_transaccion,
cod_t_trans = cod_t_trans, no_cuenta = no_cuenta, cod_sucursal =
cod_sucursal,
cod_empleado = cod_empleado, fecha_hora = fecha_hora, monto =
monto;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA TIPO_TRANSACCION
_________________________________________________________
create or replace procedure I_M_E_tipo_transaccion(
cod_t_tran integer,
nombre_tran varchar
)
is begin if inserting then
insert into tipo_transaccion(cod_t_tran, nombre_tran)
values(cod_t_tran, nombre_tran);
else if deleting then
delete from tipo_transaccion where cod_t_tran = cod_t_tran;
else if updating then
update tipo_transaccion set cod_t_tran = cod_t_tran, nombre_tran =
nombre_tran;
end if; end if; end if; end;
_________________________________________________________
PROCEDIMIENTO PARA TARJETA
_________________________________________________________
create or replace procedure I_M_E_tarjeta(
no_tarjeta integer,
no_cuenta integer,
cod_sucursal integer,
cod_clie integer,
pin integer
)
is begin if inserting then
insert into tarjeta(no_tarjeta, no_cuenta, cod_sucursal, cod_clie,
pin) values(no_tarjeta, no_cuenta, cod_sucursal, cod_clie, pin);
else if deleting then
delete from tarjeta where no_tarjeta = no_tarjeta;
else if updating then
update tarjeta set no_tarjeta = no_tarjeta, no_cuenta = no_cuenta,
cod_sucursal = cod_sucursal, cod_clie = cod_clie, pin = pin;
end if; end if; end if; end;

_________________________________________________________
PROCEDIMIENTO PARA TIPO_CHEQUE
_________________________________________________________
create or replace procedure I_M_E_tipo_cheque(
id_tipo_cheque integer,
no_chequera integer,
no_cuenta integer,
descripcion varchar
)
is begin if inserting then
insert into tipo_cheque(id_tipo_cheque, no_chequera, no_cuenta,
descripcion) values(id_tipo_cheque, no_chequera, no_cuenta,
descripcion);
else if deleting then
delete from tipo_cheque where id_tipo_cheque = id_tipo_cheque;
else if updating then
update tipo_cheque set id_tipo_cheque = id_tipo_cheque,
no_chequera = no_chequera, no_cuenta = no_cuenta, descripcion =
descripcion;
end if; end if; end if; end;

__________________________________________________________________
TRIGGERS PARA AUDITORIA
__________________________________________________________________
create or replace trigger IEM_CUENTA
before insert or update or delete
on cuenta
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CUENTA', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CUENTA', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CUENTA', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_SUCURSAL
before insert or update or delete
on sucursal
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('SUCURSAL', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('SUCURSAL', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('SUCURSAL', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_EMPLEADO
before insert or update or delete
on empleado
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('EMPLEADO', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('EMPLEADO', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('EMPLEADO', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_CLIENTE
before insert or update or delete
on cliente
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CLIENTE', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CLIENTE', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CLIENTE', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_TARJETA
before insert or update or delete
on tarjeta
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TARJETA', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TARJETA', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TARJETA', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_TIPO_TRANSACCION
before insert or update or delete
on tipo_transaccion
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_TRANSACCION', user, sysdate,
'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_TRANSACCION', user, sysdate,
'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_TRANSACCION', user, sysdate,
'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_ROL
before insert or update or delete
on rol
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('ROL', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('ROL', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('ROL', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
_______
create or replace trigger IEM_TRANSACCION
before insert or update or delete
on transaccion
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TRANSACCION', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TRANSACCION', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TRANSACCION', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_CHEQUERA
before insert or update or delete
on chequera
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUERA', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUERA', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUERA', user, sysdate, 'Update');
end if;
end if;
end if;
end;

__________________________________________________________________
create or replace trigger IEM_LOTE
before insert or update or delete
on lote
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('LOTE', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('LOTE', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('LOTE', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_TIPO_CHEQUE
before insert or update or delete
on tipo_cheque
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_CHEQUE', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_CHEQUE', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('TIPO_CHEQUE', user, sysdate, 'Update');
end if;
end if;
end if;
end;
__________________________________________________________________
create or replace trigger IEM_CHEQUE
before insert or update or delete
on cheque
for each row
begin
if inserting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUE', user, sysdate, 'Insert');
else
if deleting then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUE', user, sysdate, 'Delete');
else
if updating then
insert into auditoria (tabla,nombre_empleado, fecha_hora,
tipo_operacion) values('CHEQUE', user, sysdate, 'Update');
end if;
end if;
end if;
end;

You might also like