zoukankan      html  css  js  c++  java
  • ORACLE_TRIGGER

    PL/SQL TRIGGER Statement

    PL/SQL TRIGGER  Statement

    The trigger statemet is a especially stored procedure.It define some event about database(such as,INSERT,UPDATE,CREATE and so on).When the special database event occur and execute the corresponse FUNCTION BLOCK. 

    TRIGGER Syntax:

    create or replace trigger tri_name
    
    [befor|after|instead of] tri_event
    
    on table_naem|view_name|db_name
    
    [for each row] [when tri_condition]
    
    begin
    
      plsql_sentences;
    
    end tri_name;

     Demo Database:

    Step one:Create a table to record information for TRIGGER operator.

    Create TABLE dept_log(
            operate_tag VARCHAR2(10),
            operate_time DATE
            
    );

    Step two:Create a trigger on table dept.

    CREATE OR REPLACE TRIGGER tri_dept
           BEFORE INSERT
           ON dept
    DECLARE 
           var_tag VARCHAR2(10);
    BEGIN
           IF inserting THEN 
             var_tag:='i';
           ELSIF updating THEN
             var_tag:='u';
           ELSIF deleting THEN
             var_tag:='d';
           END IF;
           INSERT INTO dept_log 
           VALUES(var_tag,SYSDATE);
    END tri_dept;

    Step three:Launch a table operator in the trigger set.

    INSERT INTO dept VALUES(9,'a','a');

    Step four:select dept_log table information

    select * from dept_log;
  • 相关阅读:
    Puzzle, ACM/ICPC World Finals 1993, UVa227
    Puzzle, ACM/ICPC World Finals 1993, UVa227
    All in All, UVa 10340
    All in All, UVa 10340
    Box, ACM/ICPC NEERC 2004, UVa1587
    Box, ACM/ICPC NEERC 2004, UVa1587
    动态文本输出
    形态分析法
    粒子系统
    思维
  • 原文地址:https://www.cnblogs.com/yjhlsbnf/p/7775107.html
Copyright © 2011-2022 走看看