You are on page 1of 2

CREATE OR REPLACE Package taller.

zzpg_tall_se05_Pvaldivia Is
/*01*/
create table taller.zzmc_curs_pv
(cod_curs number(4) CONSTRAINT NN_zzmc_curs_pv_01 NOT NULL,
nom_cuis varchar2(50) CONSTRAINT NN_zzmc_curs_pv_02 NOT NULL);
alter table taller.zzmc_curs_pv
add constraint pk_zzmc_curs_pv primary key (cod_curs)
using index
tablespace TBS_TALLERIDX;
/*02*/
create table taller.zztc_curs_logg_pv
(cod_curs number(4) CONSTRAINT NN_zztc_curs_logg_pv_01 NOT NULL,
tip_oper varchar2(10) CONSTRAINT NN_zztc_curs_logg_pv_02 NOT NULL,
can_regi number(10) CONSTRAINT NN_zztc_curs_logg_pv_03 NOT NULL);
alter table taller.zztc_curs_logg_pv
add constraint pk_zztc_curs_logg_pv primary key (cod_curs,tip_oper)
using index
tablespace TBS_TALLERIDX;
alter table taller.zztc_curs_logg_pv
add constraint fk_zztc_curs_logg_pv_01
foreing key (cod_curs)
reference taller.zzmc_curs_pv (cod_curs);
/*03*/
create or replace trigger taller.zzmc_curs_pv_0001
after insert or update or delete taller.zzmc_curs_pv for each row
declare
cant number(10)
begin
cant:=0;
select count into cant from taller.zztc_curs_logg_pv a where :new.cod_curs=a.cod
_curs;
if inserting then
INSERT INTO taller.zztc_curs_logg_pv
(cod_curs,tip_oper,can_regi)
VALUES
(:NEW.cod_curs,'INSERT',cant+1);
commit;
elsif updating then
INSERT INTO taller.zztc_curs_logg_pv
(cod_curs,tip_oper,can_regi)
VALUES
(:NEW.cod_curs,'UPDATE',cant+1);
commit;
elsif deleting then
INSERT INTO taller.zztc_curs_logg_pv
(cod_curs,tip_oper,can_regi)
VALUES
(:NEW.cod_curs,'DELETE',cant+1);
commit;
End if;
End taller.zzmc_curs_pv_0001;