SELECT * FROMLOG;
CREATETABLELOG(
IDNUMBER(4),
CONTENT VARCHAR2(100)
)
CREATESEQUENCE T_ADD----创建序列
STARTWITH1—开始值
INCREMENTBY1—步长
NOMAXVALUE
NOMINVALUE
NOCYCLE
CACHE30;
SELECT * FROM STUDENT;
CREATEORREPLACE TRIGGER TG_ADD_ST
BEFORE INSERT
ON STUDENT
FOR EACH ROW
BEGIN
SELECT T_ADD.Nextval INTO :new.snoFROM dual;
END;
INSERTINTOSTUDENT(SNO,SNAME,SAGE,SSEX)VALUES(NULL,'傻子','22','女');
SELECT * FROMLOG;
CREATE OR REPLACE TRIGGER TG_UP_DEL_ADD_LOH
AFTERUPDATEORDELETEORINSERT
ON STUDENT
FOR EACH ROW
BEGIN
IF UPDATING THEN
INSERTINTOLOGVALUES(T_ADD.NEXTVAL,'你'||SYSDATE||'更新了'||:OLD.SNO||' '||:OLD.SNAME
||' '||:OLD.SAGE||' '||:OLD.SSEX||',修改为:'||:NEW.SNO||' '||:NEW.SNAME||' '||:NEW.SAGE||' '
||:NEW.SSEX);
ELSIF DELETING THEN
INSERTINTOLOGVALUES(T_ADD.NEXTVAL,'你于'||SYSDATE||'删除的数据为:'||:OLD.SNO||' '||:OLD.SNAME||' '
||:OLD.SAGE||' '||:OLD.SSEX);
ELSIF INSERTING THEN
INSERTINTOLOGVALUES(T_ADD.NEXTVAL,'你于'||SYSDATE||'插入的数据为:'||:NEW.SNO||' '||:NEW.SNAME||' '||:NEW.SAGE
||' '||:NEW.SSEX);
ENDIF;
END;
INSERTINTO STUDENT VALUES(T_ADD.NEXTVAL,'憨憨','22','男');
UPDATE STUDENT SET SNO='S018', SNAME='小红', SAGE='32', SSEX='女'WHERE SNO='s001';
SELECT * FROM STUDENT;
SELECT * FROMLOG;