(SNO Number Primary Key,
SNAME Varchar2(10) NOT NULL,
SEX Varchar2(4)
AGE Number
);
创建审计表STUDENT_DML(username,ins,del,upd)和DML语句触发器tr_student_dml,记录用户在STUDENT表上执行各种DML操作的次数。对应字段为哪个用户操作,增,删,改的总次数
2、创建审计表STUDENT_DML_SNAME(username,operate,operdate,opertime,value)和DML行触发器tr_sname_dml,记录用户在STUDENT表的sname字段上执行DML操作的详细信息。对应字段哪个用户操作,操作类型,日期,时间,值(student表的sname植)
3、创建审计表DATABASE_DDL(username,ddltype,operdate,opertime,object)和系统触发器tr_ddl,记录用户数据库中执行DDL操作的详细信息。
12 个解决方案
#1
作业吧?
#2
create or replace trigger trig_member_statement
after insert or delete or update on member
begin
if inserting THEN
.....
ELSIF deleting then
.....
ELSIF updating then
......
END IF;
end;
.....处不知 如何写,刚建完表,次数为null,如何加1
#3
create or replace trigger trig_member_statement
after insert or delete or update on member
begin
if inserting THEN
update STUDENT_DML set ins=nvl(ins,0)+1 where ...
--nvl(ins,0)如果ins为null的话转换为0
ELSIF deleting then
.....
ELSIF updating then
......
END IF;
end;
#4
。。。。。。
#5
#6
刚开始用户名 都不存在 如何 where 请教
#7
刚开始用户名 都不存在 如何 where 请教
#8
--楼主,参考下我这个NL异动怎么用trigger写的
--需求:
-- 使用table:TAP01,WAP01
-- 请建立一个TAP01之TABLE TRIGGER,产生NL异动TABLE(WAP01)。
-- 注:1.每笔测试资料处理(INSERT or UPDATE or DELETE)加入WAP01时间不可相同。
-- 2.TRIGGER时机为AFTER INSERT,UPDATE,DELETE。
-- 3.详细TABLE说明请参考TEST4_INITDATA.sql。
-- 4.测试资料请运行TEST4_DATA05.sql
--初始数据脚本?
--tap01庫存調整檔
CREATE TABLE tap01
(deptno number(4) --部門
,PmDat varchar2(8) --生產日期
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
,CONSTRAINT pk_tap01 PRIMARY KEY (deptno,vhno)
);
--wap01庫存調整NL異動檔
CREATE TABLE wap01
(txdat varchar2(8) --系統年月日(YYYYMMDD)
,txtm varchar2(6) --系統時分(時以24小時制)
,nl varchar2(1) --N:正常資料, L:取消資料
,deptno number(4) --部門
,PmDat varchar2(8) --生產日期(YYYYMMDD)
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
);
--trigger
create or replace trigger trigger_nl
after insert or update or delete on tap01
for each row
declare
wrk_txdat varchar2(8);
wrk_txtm varchar2(6);
begin
SELECT (TO_CHAR(sysdate,'YYYY'))||TO_CHAR(sysdate,'MM')||TO_CHAR(sysdate,'DD') into wrk_txdat FROM dual;
SELECT TO_CHAR(sysdate,'hh24miss') into wrk_txtm FROM dual;
if updating or deleting then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
select wrk_txdat,wrk_txtm,'L',deptno,PmDat,VhNo,pdno,rsid,AdjQty from wap01 where deptno=:old.deptno and PmDat=:old.PmDat and VhNo=:old.VhNo and pdno=:old.pdno ;
end if;
if inserting or updating then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
values(wrk_txdat,wrk_txtm,'N',:new.deptno,:new.PmDat,:new.VhNo,:new.pdno,:new.rsid,:new.AdjQty);
end if;
end trigger_nl;
--测试:
INSERT INTO tap01 VALUES(20,'20060501','A20001','PRODUCT001','A',10000);
INSERT INTO tap01 VALUES(20,'20060501','A20002','PRODUCT002','A',5000);
INSERT INTO tap01 VALUES(20,'20060501','A20003','PRODUCT003','A',11000);
INSERT INTO tap01 VALUES(20,'20060502','A20004','PRODUCT001','B',5000);
INSERT INTO tap01 VALUES(30,'20060511','A30001','PRODUCT101','A',1);
INSERT INTO tap01 VALUES(30,'20060511','A30002','PRODUCT102','A',5);
INSERT INTO tap01 VALUES(30,'20060511','A30003','PRODUCT103','A',11);
INSERT INTO tap01 VALUES(30,'20060512','A30004','PRODUCT101','B',5);
INSERT INTO tap01 VALUES(20,'20060521','A20005','PRODUCT002','A',5000);
DELETE FROM tap01 WHERE deptno=20 and vhno='A20005';
UPDATE tap01 SET adjqty=6 WHERE deptno=30 and vhno='A30003';
commit;
--ps:
--至于你说你的,要获取哪个用户,客户端的话,可以用这个获取登录用户
SELECT SYS_CONTEXT('USERENV','CURRENT_USER') current_user FROM dual;
--客户端IP地址
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address FROM dual;
--服务器名
SELECT SYS_CONTEXT('USERENV','DB_NAME') db_name FROM dual;
#9
--楼主,参考下我这个NL异动怎么用trigger写的
--需求:
-- 使用table:TAP01,WAP01
-- 请建立一个TAP01之TABLE TRIGGER,产生NL异动TABLE(WAP01)。
-- 注:1.每笔测试资料处理(INSERT or UPDATE or DELETE)加入WAP01时间不可相同。
-- 2.TRIGGER时机为AFTER INSERT,UPDATE,DELETE。
-- 3.详细TABLE说明请参考TEST4_INITDATA.sql。
-- 4.测试资料请运行TEST4_DATA05.sql
--初始数据脚本?
--tap01庫存調整檔
CREATE TABLE tap01
(deptno number(4) --部門
,PmDat varchar2(8) --生產日期
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
,CONSTRAINT pk_tap01 PRIMARY KEY (deptno,vhno)
);
--wap01庫存調整NL異動檔
CREATE TABLE wap01
(txdat varchar2(8) --系統年月日(YYYYMMDD)
,txtm varchar2(6) --系統時分(時以24小時制)
,nl varchar2(1) --N:正常資料, L:取消資料
,deptno number(4) --部門
,PmDat varchar2(8) --生產日期(YYYYMMDD)
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
);
--trigger
create or replace trigger trigger_nl
after insert or update or delete on tap01
for each row
declare
wrk_txdat varchar2(8);
wrk_txtm varchar2(6);
begin
SELECT (TO_CHAR(sysdate,'YYYY'))||TO_CHAR(sysdate,'MM')||TO_CHAR(sysdate,'DD') into wrk_txdat FROM dual;
SELECT TO_CHAR(sysdate,'hh24miss') into wrk_txtm FROM dual;
if updating or deleting then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
select wrk_txdat,wrk_txtm,'L',deptno,PmDat,VhNo,pdno,rsid,AdjQty from wap01 where deptno=:old.deptno and PmDat=:old.PmDat and VhNo=:old.VhNo and pdno=:old.pdno ;
end if;
if inserting or updating then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
values(wrk_txdat,wrk_txtm,'N',:new.deptno,:new.PmDat,:new.VhNo,:new.pdno,:new.rsid,:new.AdjQty);
end if;
end trigger_nl;
--测试:
INSERT INTO tap01 VALUES(20,'20060501','A20001','PRODUCT001','A',10000);
INSERT INTO tap01 VALUES(20,'20060501','A20002','PRODUCT002','A',5000);
INSERT INTO tap01 VALUES(20,'20060501','A20003','PRODUCT003','A',11000);
INSERT INTO tap01 VALUES(20,'20060502','A20004','PRODUCT001','B',5000);
INSERT INTO tap01 VALUES(30,'20060511','A30001','PRODUCT101','A',1);
INSERT INTO tap01 VALUES(30,'20060511','A30002','PRODUCT102','A',5);
INSERT INTO tap01 VALUES(30,'20060511','A30003','PRODUCT103','A',11);
INSERT INTO tap01 VALUES(30,'20060512','A30004','PRODUCT101','B',5);
INSERT INTO tap01 VALUES(20,'20060521','A20005','PRODUCT002','A',5000);
DELETE FROM tap01 WHERE deptno=20 and vhno='A20005';
UPDATE tap01 SET adjqty=6 WHERE deptno=30 and vhno='A30003';
commit;
--ps:
--至于你说你的,要获取哪个用户,客户端的话,可以用这个获取登录用户
SELECT SYS_CONTEXT('USERENV','CURRENT_USER') current_user FROM dual;
--客户端IP地址
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address FROM dual;
--服务器名
SELECT SYS_CONTEXT('USERENV','DB_NAME') db_name FROM dual;
#10
create or replace trigger tr_student_dml
after insert or update or delete on student
for each row
begin
if inserting then
update student_dml set ins=nvl(ins,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,1,0,0);
end if;
else deleting then
update student_dml set del=nvl(del,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,0,1,0);
end if;
else updating then
update student_dml set upd=nvl(upd,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,0,0,1);
end if;
end if;
end;
返回受影响行数为0时表示没用户,那就插入数据 这样的思路 报错 求教
Line # = 7 Column # = 16 Error Text = PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
:= . ( @ % ;
Line # = 12 Column # = 16 Error Text = PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
:= . ( @ % ;
Line # = 18 Column # = 4 Error Text = PLS-00103: Encountered the symbol ";" when expecting one of the following:
if
#11
求 救 救 啊
#12
scott@YPCOST> ed
已写入 file afiedt.buf
1 CREATE TABLE STUDENT
2 (SNO Number Primary Key,
3 SNAME varchar2(10) NOT NULL,
4 SEX varchar2(4),
5 AGE Number
6* )
scott@YPCOST> /
表已创建。
scott@YPCOST> ed
已写入 file afiedt.buf
1 create table STUDENT_DML
2 (username varchar2(10),
3 ins number,
4 del number,
5* upd number)
scott@YPCOST> /
表已创建。
scott@YPCOST> ed
已写入 file afiedt.buf
1 create or replace trigger tri_dml
2 after delete or update or insert on student
3 for each row
4 declare
5 nflag number(1);--student_dml是否为空
6 operator_name varchar2(20);--保存对student_dml表的操作员
7 begin
8 select count(*) into nflag from student_dml;
9 select user into operator_name from global_name;
10 if nflag>0 then
11 if inserting then
12 update student_dml set ins=nvl(ins,0)+1;
13 end if;
14 if updating then
15 update student_dml set upd=nvl(upd,0)+1;
16 end if;
17 if deleting then
18 update student_dml set del=nvl(del,0)+1;
19 end if;
20 else
21 if inserting then
22 insert into student_dml(username,ins) values('sdf',1);
23 end if;
24 if updating then
25 insert into student_dml(username,upd) values('sdf',1);
26 end if;
27 if deleting then
28 insert into student_dml(username,del) values('sdf',1);
29 end if;
30 end if;
31* end;
scott@YPCOST> insert into student values(1100,'df','M',23);
已创建 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> insert into student values(232,'fsd','F',34);
已创建 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2
scott@YPCOST> delete student where sno=232;
已删除 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2 1
scott@YPCOST> update student set sno=7788 where sno=1100;
已更新 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2 1 1
#1
作业吧?
#2
create or replace trigger trig_member_statement
after insert or delete or update on member
begin
if inserting THEN
.....
ELSIF deleting then
.....
ELSIF updating then
......
END IF;
end;
.....处不知 如何写,刚建完表,次数为null,如何加1
#3
create or replace trigger trig_member_statement
after insert or delete or update on member
begin
if inserting THEN
update STUDENT_DML set ins=nvl(ins,0)+1 where ...
--nvl(ins,0)如果ins为null的话转换为0
ELSIF deleting then
.....
ELSIF updating then
......
END IF;
end;
#4
。。。。。。
#5
#6
刚开始用户名 都不存在 如何 where 请教
#7
刚开始用户名 都不存在 如何 where 请教
#8
--楼主,参考下我这个NL异动怎么用trigger写的
--需求:
-- 使用table:TAP01,WAP01
-- 请建立一个TAP01之TABLE TRIGGER,产生NL异动TABLE(WAP01)。
-- 注:1.每笔测试资料处理(INSERT or UPDATE or DELETE)加入WAP01时间不可相同。
-- 2.TRIGGER时机为AFTER INSERT,UPDATE,DELETE。
-- 3.详细TABLE说明请参考TEST4_INITDATA.sql。
-- 4.测试资料请运行TEST4_DATA05.sql
--初始数据脚本?
--tap01庫存調整檔
CREATE TABLE tap01
(deptno number(4) --部門
,PmDat varchar2(8) --生產日期
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
,CONSTRAINT pk_tap01 PRIMARY KEY (deptno,vhno)
);
--wap01庫存調整NL異動檔
CREATE TABLE wap01
(txdat varchar2(8) --系統年月日(YYYYMMDD)
,txtm varchar2(6) --系統時分(時以24小時制)
,nl varchar2(1) --N:正常資料, L:取消資料
,deptno number(4) --部門
,PmDat varchar2(8) --生產日期(YYYYMMDD)
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
);
--trigger
create or replace trigger trigger_nl
after insert or update or delete on tap01
for each row
declare
wrk_txdat varchar2(8);
wrk_txtm varchar2(6);
begin
SELECT (TO_CHAR(sysdate,'YYYY'))||TO_CHAR(sysdate,'MM')||TO_CHAR(sysdate,'DD') into wrk_txdat FROM dual;
SELECT TO_CHAR(sysdate,'hh24miss') into wrk_txtm FROM dual;
if updating or deleting then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
select wrk_txdat,wrk_txtm,'L',deptno,PmDat,VhNo,pdno,rsid,AdjQty from wap01 where deptno=:old.deptno and PmDat=:old.PmDat and VhNo=:old.VhNo and pdno=:old.pdno ;
end if;
if inserting or updating then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
values(wrk_txdat,wrk_txtm,'N',:new.deptno,:new.PmDat,:new.VhNo,:new.pdno,:new.rsid,:new.AdjQty);
end if;
end trigger_nl;
--测试:
INSERT INTO tap01 VALUES(20,'20060501','A20001','PRODUCT001','A',10000);
INSERT INTO tap01 VALUES(20,'20060501','A20002','PRODUCT002','A',5000);
INSERT INTO tap01 VALUES(20,'20060501','A20003','PRODUCT003','A',11000);
INSERT INTO tap01 VALUES(20,'20060502','A20004','PRODUCT001','B',5000);
INSERT INTO tap01 VALUES(30,'20060511','A30001','PRODUCT101','A',1);
INSERT INTO tap01 VALUES(30,'20060511','A30002','PRODUCT102','A',5);
INSERT INTO tap01 VALUES(30,'20060511','A30003','PRODUCT103','A',11);
INSERT INTO tap01 VALUES(30,'20060512','A30004','PRODUCT101','B',5);
INSERT INTO tap01 VALUES(20,'20060521','A20005','PRODUCT002','A',5000);
DELETE FROM tap01 WHERE deptno=20 and vhno='A20005';
UPDATE tap01 SET adjqty=6 WHERE deptno=30 and vhno='A30003';
commit;
--ps:
--至于你说你的,要获取哪个用户,客户端的话,可以用这个获取登录用户
SELECT SYS_CONTEXT('USERENV','CURRENT_USER') current_user FROM dual;
--客户端IP地址
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address FROM dual;
--服务器名
SELECT SYS_CONTEXT('USERENV','DB_NAME') db_name FROM dual;
#9
--楼主,参考下我这个NL异动怎么用trigger写的
--需求:
-- 使用table:TAP01,WAP01
-- 请建立一个TAP01之TABLE TRIGGER,产生NL异动TABLE(WAP01)。
-- 注:1.每笔测试资料处理(INSERT or UPDATE or DELETE)加入WAP01时间不可相同。
-- 2.TRIGGER时机为AFTER INSERT,UPDATE,DELETE。
-- 3.详细TABLE说明请参考TEST4_INITDATA.sql。
-- 4.测试资料请运行TEST4_DATA05.sql
--初始数据脚本?
--tap01庫存調整檔
CREATE TABLE tap01
(deptno number(4) --部門
,PmDat varchar2(8) --生產日期
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
,CONSTRAINT pk_tap01 PRIMARY KEY (deptno,vhno)
);
--wap01庫存調整NL異動檔
CREATE TABLE wap01
(txdat varchar2(8) --系統年月日(YYYYMMDD)
,txtm varchar2(6) --系統時分(時以24小時制)
,nl varchar2(1) --N:正常資料, L:取消資料
,deptno number(4) --部門
,PmDat varchar2(8) --生產日期(YYYYMMDD)
,VhNo varchar2(10) --本單編號
,pdno varchar2(20) --產品編號
,rsid varchar2(3) --A:庫存增加, B:庫存減少
,AdjQty number(20,5) --調整數量
);
--trigger
create or replace trigger trigger_nl
after insert or update or delete on tap01
for each row
declare
wrk_txdat varchar2(8);
wrk_txtm varchar2(6);
begin
SELECT (TO_CHAR(sysdate,'YYYY'))||TO_CHAR(sysdate,'MM')||TO_CHAR(sysdate,'DD') into wrk_txdat FROM dual;
SELECT TO_CHAR(sysdate,'hh24miss') into wrk_txtm FROM dual;
if updating or deleting then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
select wrk_txdat,wrk_txtm,'L',deptno,PmDat,VhNo,pdno,rsid,AdjQty from wap01 where deptno=:old.deptno and PmDat=:old.PmDat and VhNo=:old.VhNo and pdno=:old.pdno ;
end if;
if inserting or updating then
insert into wap01(txdat,txtm,nl,deptno,PmDat,VhNo,pdno,rsid,AdjQty)
values(wrk_txdat,wrk_txtm,'N',:new.deptno,:new.PmDat,:new.VhNo,:new.pdno,:new.rsid,:new.AdjQty);
end if;
end trigger_nl;
--测试:
INSERT INTO tap01 VALUES(20,'20060501','A20001','PRODUCT001','A',10000);
INSERT INTO tap01 VALUES(20,'20060501','A20002','PRODUCT002','A',5000);
INSERT INTO tap01 VALUES(20,'20060501','A20003','PRODUCT003','A',11000);
INSERT INTO tap01 VALUES(20,'20060502','A20004','PRODUCT001','B',5000);
INSERT INTO tap01 VALUES(30,'20060511','A30001','PRODUCT101','A',1);
INSERT INTO tap01 VALUES(30,'20060511','A30002','PRODUCT102','A',5);
INSERT INTO tap01 VALUES(30,'20060511','A30003','PRODUCT103','A',11);
INSERT INTO tap01 VALUES(30,'20060512','A30004','PRODUCT101','B',5);
INSERT INTO tap01 VALUES(20,'20060521','A20005','PRODUCT002','A',5000);
DELETE FROM tap01 WHERE deptno=20 and vhno='A20005';
UPDATE tap01 SET adjqty=6 WHERE deptno=30 and vhno='A30003';
commit;
--ps:
--至于你说你的,要获取哪个用户,客户端的话,可以用这个获取登录用户
SELECT SYS_CONTEXT('USERENV','CURRENT_USER') current_user FROM dual;
--客户端IP地址
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') ip_address FROM dual;
--服务器名
SELECT SYS_CONTEXT('USERENV','DB_NAME') db_name FROM dual;
#10
create or replace trigger tr_student_dml
after insert or update or delete on student
for each row
begin
if inserting then
update student_dml set ins=nvl(ins,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,1,0,0);
end if;
else deleting then
update student_dml set del=nvl(del,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,0,1,0);
end if;
else updating then
update student_dml set upd=nvl(upd,0)+1 where username=ora_login_user;
if sql%rowcount=0 then
insert into student_dml values (ora_login_user,0,0,1);
end if;
end if;
end;
返回受影响行数为0时表示没用户,那就插入数据 这样的思路 报错 求教
Line # = 7 Column # = 16 Error Text = PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
:= . ( @ % ;
Line # = 12 Column # = 16 Error Text = PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
:= . ( @ % ;
Line # = 18 Column # = 4 Error Text = PLS-00103: Encountered the symbol ";" when expecting one of the following:
if
#11
求 救 救 啊
#12
scott@YPCOST> ed
已写入 file afiedt.buf
1 CREATE TABLE STUDENT
2 (SNO Number Primary Key,
3 SNAME varchar2(10) NOT NULL,
4 SEX varchar2(4),
5 AGE Number
6* )
scott@YPCOST> /
表已创建。
scott@YPCOST> ed
已写入 file afiedt.buf
1 create table STUDENT_DML
2 (username varchar2(10),
3 ins number,
4 del number,
5* upd number)
scott@YPCOST> /
表已创建。
scott@YPCOST> ed
已写入 file afiedt.buf
1 create or replace trigger tri_dml
2 after delete or update or insert on student
3 for each row
4 declare
5 nflag number(1);--student_dml是否为空
6 operator_name varchar2(20);--保存对student_dml表的操作员
7 begin
8 select count(*) into nflag from student_dml;
9 select user into operator_name from global_name;
10 if nflag>0 then
11 if inserting then
12 update student_dml set ins=nvl(ins,0)+1;
13 end if;
14 if updating then
15 update student_dml set upd=nvl(upd,0)+1;
16 end if;
17 if deleting then
18 update student_dml set del=nvl(del,0)+1;
19 end if;
20 else
21 if inserting then
22 insert into student_dml(username,ins) values('sdf',1);
23 end if;
24 if updating then
25 insert into student_dml(username,upd) values('sdf',1);
26 end if;
27 if deleting then
28 insert into student_dml(username,del) values('sdf',1);
29 end if;
30 end if;
31* end;
scott@YPCOST> insert into student values(1100,'df','M',23);
已创建 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> insert into student values(232,'fsd','F',34);
已创建 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2
scott@YPCOST> delete student where sno=232;
已删除 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2 1
scott@YPCOST> update student set sno=7788 where sno=1100;
已更新 1 行。
scott@YPCOST> commit;
提交完成。
scott@YPCOST> select * from student_dml;
USERNAME INS DEL UPD
---------- ---------- ---------- ----------
sdf 2 1 1