-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig.sql
66 lines (60 loc) · 1.55 KB
/
trig.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
drop trigger student_trigger;
drop trigger enrollments_trigger;
-- trigger for students table
create or replace trigger student_trigger
after insert or update or delete
on students
for each row
declare
log_action logs.operation%type;
myuser logs.who%type;
mytime date;
mysid logs.key_value%type;
begin
if INSERTING then
log_action := 'Insert';
mysid := :new.sid;
elsif UPDATING then
log_action := 'Update';
mysid := :old.sid;
elsif DELETING then
log_action := 'Delete';
mysid := :old.sid;
else
DBMS_OUTPUT.PUT_LINE('This code is not reachable.');
end if;
select user into myuser from dual;
select sysdate into mytime from dual;
insert into logs values(log_id.nextval,myuser,mytime,'students',log_action,mysid);
end;
/
-- #############################################################
-- # trigger for enrollments table
create or replace trigger enrollments_trigger
after insert or update or delete
on enrollments
for each row
declare
log_action logs.operation%type;
myuser logs.who%type;
mytime date;
mykey logs.key_value%type;
begin
if INSERTING then
log_action := 'Insert';
mykey := :new.sid || :new.classid;
elsif UPDATING then
log_action := 'Update';
mykey := :old.sid || :old.classid;
elsif DELETING then
log_action := 'Delete';
mykey := :old.sid || :old.classid;
else
DBMS_OUTPUT.PUT_LINE('This code is not reachable.');
end if;
select user into myuser from dual;
select sysdate into mytime from dual;
insert into logs values(log_id.nextval,myuser,mytime,'enrollments',log_action,mykey);
end;
/
show errors