Oracle中触发器的使用例子
2009-01-20 14:42
375 查看
编写简单触发器,实现当在学生信息表(StudInfo)中添加记录后,在SQL*PLUS中显
示添加的各项值,当在学生信息表(StudInfo)中删除记录后,在SQL*PLUS中显示删
除的各项值,当在学生信息表(StudInfo)中更新记录后,在SQL*PLUS中显示更新前
和更新后的各项值。
create or replace trigger triginsert
after insert on studinfo
for each row
begin
dbms_output.put_line('刚插入的各项值如下:');
dbms_output.put_line('学号:'|| :new.studno || ',姓名:' || :new.studname ||
',性别:' || :new.studsex || ',出生日期:' || :new.studbirthday ||
',班级编号' || :new.classid);
end;
insert into classinfo
values('20060704','计科06',default)
create or replace trigger trigdelete
after delete on studinfo
for each row
begin
dbms_output.put_line('刚删除的各项值如下:');
dbms_output.put_line('学号:'|| :old.studno || ',姓名:' || :old.studname ||
',性别:' || :old.studsex || ',出生日期:' || :old.studbirthday ||
',班级编号' || :old.classid);
end;
delete from studinfo where studno='20060704067'
create or replace trigger trigupdate
after update on studinfo
for each row
begin
dbms_output.put_line('更新后的各项值如下:');
dbms_output.put_line('学号:'|| :new.studno || ',姓名:' || :new.studname ||
',性别:' || :new.studsex || ',出生日期:' || :new.studbirthday ||
',班级编号' || :new.classid);
dbms_output.put_line('更新前的各项值如下:');
dbms_output.put_line('学号:'|| :old.studno || ',姓名:' || :old.studname ||
',性别:' || :old.studsex || ',出生日期:' || :old.studbirthday ||
',班级编号' || :old.classid);
end;
示添加的各项值,当在学生信息表(StudInfo)中删除记录后,在SQL*PLUS中显示删
除的各项值,当在学生信息表(StudInfo)中更新记录后,在SQL*PLUS中显示更新前
和更新后的各项值。
create or replace trigger triginsert
after insert on studinfo
for each row
begin
dbms_output.put_line('刚插入的各项值如下:');
dbms_output.put_line('学号:'|| :new.studno || ',姓名:' || :new.studname ||
',性别:' || :new.studsex || ',出生日期:' || :new.studbirthday ||
',班级编号' || :new.classid);
end;
insert into classinfo
values('20060704','计科06',default)
create or replace trigger trigdelete
after delete on studinfo
for each row
begin
dbms_output.put_line('刚删除的各项值如下:');
dbms_output.put_line('学号:'|| :old.studno || ',姓名:' || :old.studname ||
',性别:' || :old.studsex || ',出生日期:' || :old.studbirthday ||
',班级编号' || :old.classid);
end;
delete from studinfo where studno='20060704067'
create or replace trigger trigupdate
after update on studinfo
for each row
begin
dbms_output.put_line('更新后的各项值如下:');
dbms_output.put_line('学号:'|| :new.studno || ',姓名:' || :new.studname ||
',性别:' || :new.studsex || ',出生日期:' || :new.studbirthday ||
',班级编号' || :new.classid);
dbms_output.put_line('更新前的各项值如下:');
dbms_output.put_line('学号:'|| :old.studno || ',姓名:' || :old.studname ||
',性别:' || :old.studsex || ',出生日期:' || :old.studbirthday ||
',班级编号' || :old.classid);
end;
相关文章推荐
- Oracle学习记录之使用自定义函数和触发器实现主键动态生成
- Oracle游标、参数的使用例子
- 使用触发器实现记录oracle用户登录失败信息到alert.log日志文件
- oracle JDBC使用例子
- oracle中使用SQL递归语句的例子
- Oracle 序列 触发器的使用
- Oracle中存储器(procedure)和触发器(trigger)的小例子
- Oracle优化之旅:使用leading, use_nl, rownum调优例子
- oracle中使用触发器来实现自增长
- 一个ORACLE的DDL触发器例子
- ORACLE中使用动态游标的例子
- oracle 中使用触发器自动生成UUID
- 使用触发器记录oracle用户登陆信息
- oracle if else elsif 使用例子
- Oracle--序列和触发器的使用
- 使用Hibernate插入oracle Date类型的例子
- oracle 使用触发器更新插入列的id
- oracle中触发器中:new和:old 的使用方法--4
- Oracle序列和触发器的使用