CREACIÓN DE TRIGGERS EN ORACLE 12C CON ESQUEMA HR
TABLA AUDITORIA CON REGIONS
--CREAR TABLA AUDITORIA
create table audita_insert_regions(
region_id number,
region_name varchar2(25),
user_insert varchar2(25),
fecha_insert date,
hora_insert varchar2(12),
servidor varchar2(15),
ip varchar2(25)
);
--CREAR EL TRIGGER
create or replace trigger tr_insert_regions
after insert
on hr.regions
for each row
declare
v_usu varchar2(25);
v_fecha date;
v_hora varchar(12);
v_serv varchar2(15);
v_ip varchar2(25);
begin
select user into v_usu from dual;
select sysdate into v_fecha from dual;
select to_char(sysdate, 'HH12:MI:SS') into v_hora from dual;
select SYS_CONTEXT('USERENV', 'HOST')into v_serv from dual;
select SYS_CONTEXT('USERENV', 'IP_ADDRESS')into v_ip from dual;
insert into audita_insert_regions
values(:new.region_id, :new.region_name, v_usu, v_fecha, v_hora, v_serv, v_ip);
end;
--by Ing. Jhonatan Abal
TABLA AUDITORIA CON REGIONS
--CREAR TABLA AUDITORIA
create table audita_insert_regions(
region_id number,
region_name varchar2(25),
user_insert varchar2(25),
fecha_insert date,
hora_insert varchar2(12),
servidor varchar2(15),
ip varchar2(25)
);
--CREAR EL TRIGGER
create or replace trigger tr_insert_regions
after insert
on hr.regions
for each row
declare
v_usu varchar2(25);
v_fecha date;
v_hora varchar(12);
v_serv varchar2(15);
v_ip varchar2(25);
begin
select user into v_usu from dual;
select sysdate into v_fecha from dual;
select to_char(sysdate, 'HH12:MI:SS') into v_hora from dual;
select SYS_CONTEXT('USERENV', 'HOST')into v_serv from dual;
select SYS_CONTEXT('USERENV', 'IP_ADDRESS')into v_ip from dual;
insert into audita_insert_regions
values(:new.region_id, :new.region_name, v_usu, v_fecha, v_hora, v_serv, v_ip);
end;
--by Ing. Jhonatan Abal
Comentarios