Home > Database > Mysql Tutorial > body text

Oracle触发器详细介绍

WBOY
Release: 2016-06-07 15:14:11
Original
943 people have browsed it

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 触发器 是特定事件出现的时候,自动执行的代码块。类似于存储过程,但是用户不能直接调用他们。 功能: 1、 允许 / 限制对表的修改 2、 自动生成派生列,比如自增字段 3、 强制数据一致性 4、 提供

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入

触发器

是特定事件出现的时候,自动执行的代码块。类似于存储过程,但是用户不能直接调用他们。

功能:

1、 允许/限制对表的修改

2、 自动生成派生列,比如自增字段

3、 强制数据一致性

4、 提供审计和日志记录

5、 防止无效的事务处理

6、 启用复杂的业务逻辑

开始

create trigger biufer_employees_department_id

       before insert or update

              of department_id

              on employees

       referencing old as old_value

                       new as new_value

       for each row

       when (new_value.department_id80 )

begin

       :new_value.commission_pct :=0;

end;

/

触发器的组成部分:

1、 触发器名称

2、 触发语句

3、 触发器限制

4、 触发操作

1、 触发器名称

create trigger biufer_employees_department_id

命名习惯:

biuferbefore insert update for each row

employees 表名

department_id 列名

2、 触发语句

比如:

表或视图上的DML语句

DDL语句

数据库关闭或启动,startup shutdown 等等

before insert or update

              of department_id

              on employees

       referencing old as old_value

                       new as new_value

       for each row

说明:

1、 无论是否规定了department_id ,对employees表进行insert的时候

2、 employees表的department_id列进行update的时候

3、 触发器限制

when (new_value.department_id80 )

限制不是必须的。此例表示如果列department_id不等于80的时候,触发器就会执行。

其中的new_value是代表更新之后的值。

4、 触发操作

是触发器的主体

begin

       :new_value.commission_pct :=0;

end;

主体很简单,就是将更新后的commission_pct列置为0

触发:

insert into employees(employee_id,

last_name,first_name,hire_date,job_id,email,department_id,salary,commission_pct )

values( 12345,’Chen’,’Donny’, sysdate, 12, ‘donny@hotmail.com’,60,10000,.25);

select commission_pct from employees where employee_id=12345;

触发器不会通知用户,便改变了用户的输入值。

触发器类型:

1、 语句触发器

2、 行触发器

3、 INSTEAD OF 触发器

4、 系统条件触发器

5、 用户事件触发器

 

[1] [2] 

Oracle触发器详细介绍

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!