Home  >  Article  >  Database  >  Oracle Database 10g PL/SQL Programming

Oracle Database 10g PL/SQL Programming

WBOY
WBOYOriginal
2016-06-07 16:46:41916browse

Oracle Database 10g PL/SQL Programming - PL/SQL块之触发器简单应用

触发器提供了PL/SQL的一种特殊实现。它们存储在数据库中,但又不是存储过程或函数。触发器由事件驱动,并且与执行在数据库离得某种操作关联在一起。让我们来研究下面的示例代码:

CREATE OR REPLACE TRIGGER nimeng_trig

AFTER UPDATE OF first_name

ON authors

FOR EACH ROW

WHEN (OLD.first_name != NEW.first_name)

BEGIN

DBMS_OUTPUT.PUT_LINE('First Name '

||:OLD.first_name

||' has change to '

||:NEW.first_name);

END;

这里我们创建了一个名为nimeng_trig的触发器,这个触发器是建立在authors表上的,只要更新该表的first_name列,,这个触发器就会被触发。我们来测试一下这个触发器:

UPDATE authors

SET first_name = 'NIMENG'

WHERE first_name = 'Ron';

触发器立即触发,并在屏幕上显示信息:

first name Ron has change to NIMENG

通过这个例子,可以对触发器的建立、使用有一个简单的了解。

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Statement:
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