ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Trigger Introduction

Trigger Introduction

原创 Linux操作系统 作者:yanggq 时间:2019-05-07 18:48:06 0 删除 编辑
Introduction

A trigger is a compiled procedure stored in the database. The language you use is PL/SQL. You code and compile a trigger in the same manner you code stored procedures. The following is the SQL*Plus session that creates and demonstrates a simple Insert Row trigger. This trigger calls DBMS_OUTPUT to print "executing temp_air" for each row inserted.

SQL> set feedback off
SQL> CREATE TABLE temp (N NUMBER);
SQL> CREATE OR REPLACE TRIGGER temp_air
  2  AFTER INSERT ON TEMP
  3  FOR EACH ROW
  4  BEGIN
  5  dbms_output.put_line('executing temp_air');
  6  END;
7   /
8   SQL> INSERT INTO temp VALUES (1);      -- insert 1 row
executing temp_air
SQL> INSERT INTO temp SELECT * FROM temp;  -- insert 1 row
executing temp_air
SQL> INSERT INTO temp SELECT * FROM temp;  -- inserts 2 rows
executing temp_air
executing temp_air
SQL>

The third INSERT statement inserted two rows into TEMP, even though this was a single SQL statement. Most insert SQL statements insert a single row; however, as shown earlier, multiple rows can be inserted with one statement.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26706/viewspace-64556/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 人生的6大败局
请登录后发表评论 登录
全部评论

注册时间:2002-10-29

  • 博文量
    54
  • 访问量
    40942