Friday, May 23, 2008

sequence + trigger

create sequence seq_peserta
increment by 1
start with 0001
maxvalue 9999;

create or replace trigger bef_ins_row_peserta
before insert on peserta
for each row
begin
if inserting then
if (:new.id_peserta is NULL) then
select 'PS'||seq_peserta.nextval into :new.id_peserta from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/

insert into peserta values('','rahmat','pga56','085228725252');

================================================
create sequence seq_pengajar
increment by 1
start with 0001
maxvalue 9999;

create or replace trigger bef_ins_row_pengajar
before insert on pengajar
for each row
begin
if inserting then
if (:new.id_pengajar is NULL) then
select 'PG'||seq_pengajar.nextval into :new.id_pengajar from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/
=================================================
create sequence seq_ruang
increment by 1
start with 0001
maxvalue 9999;

create or replace trigger bef_ins_row_ruang
before insert on ruang
for each row
begin
if inserting then
if (:new.id_ruang is NULL) then
select 'RU'||seq_ruang.nextval into :new.id_ruang from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/
======================================
create sequence seq_kursus
increment by 1
start with 0001
maxvalue 9999;

create or replace trigger bef_ins_row_kursus
before insert on kursus
for each row
begin
if inserting then
if (:new.id_kursus is NULL) then
select 'KU'||seq_kursus.nextval into :new.id_kursus from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/
===========================
create sequence seq_jadwal
increment by 1
start with 0001
maxvalue 9999;

create or replace trigger bef_ins_row_jadwal
before insert on jadwal
for each row
begin
if inserting then
if (:new.id_jadwal is NULL) then
select 'JA'||seq_jadwal.nextval into :new.id_jadwal from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/
=========================================
create or replace trigger bef_ins_row_kuota_kursus
before insert on kursus
for each row
begin
if inserting then
if (:new.id_kursus is NULL) then
select 'KU'||seq_kursus.nextval into :new.id_kursus from dual;
else
raise_application_error(-20103,'wrong initial status');
end if;
end if;
end;
/

No comments:

Post a Comment