简介 目录 评价 推荐
  • 慕雪9027749 2024-02-01

    触发器

    应用场景:

    1. 复杂的安全性检查

    2. 数据确认

    3. 实现审计功能

    4. 完成数据的备份和同步

    触发器的语法

    触发器类型

    1. 语句级触发器和行级触发器

    案例

    0赞 · 0采集
  • 旧莳0 2023-10-26
    /*
    触发器场景四:数据备份和同步
    
    */
    create table emp_back as SELECT * FROM EMP;
    
    create or replace trigger back_sal_tri
    after UPDATE
    on EMP
    for each ROW
    DECLARE
    BEGIN
    --当员工薪资更新后自动备份
    UPDATE emp_back set sal = :new.sal where EMPNO = :new.EMPNO;
    
    
    END;
    
    SELECT sal from EMP where EMPNO = '7499';
    
    SELECT sal from EMP_back where EMPNO = '7499';
    
    update emp set sal = sal + 100 where empno = '7499'
    0赞 · 0采集
  • 旧莳0 2023-10-26
    /*触发器应用场景三: 数据的审计---》基于值得审计功能
    
    例子:给员工涨工资,当涨后的薪水超过6000块时候,审计该员工的信息
    
    创建表,用于保存审计信息
    */
    create table outdit_info(inforoudname VARCHAR2(2000));
    
    create or replace trigger outdit_emp_sal_tri
    after UPDATE
    on EMP
    for each row 
    BEGIN
    IF :new.sal > 6000 THEN
     insert INTO outdit_info VALUES (:new.EMPNO||' '||:new.ename||' '||:new.sal);
    
    
    end if;
    
    END;
    
    
    UPDATE emp set sal = sal + 3000;
    0赞 · 0采集
  • 斯巴达汉子 2021-12-22

    触发器使用作用场景:

    1. 复杂的安全性检查

    2. 数据的确认

    3. 数据库的审计

    4. 数据的备份和同步


    0赞 · 0采集
  • 斯巴达汉子 2021-12-22

    oracle中触发器是同步备份

    快照是异步备份

    0赞 · 0采集
  • 慕设计4302654 2021-11-09

    触发器案例四:数据的备份和同步

    利用触发

    当给员工涨完工资后,自动备份新的工资到备份表中

    创建备份表

    http://img3.mukewang.com/6189ee4e0001a7a703430031.jpg

    创建触发器

    http://img4.mukewang.com/6189ef060001133b03750142.jpg

    0赞 · 0采集
  • 慕设计4302654 2021-11-09

    触发器案例三:数据库的审计功能

    基于值的审计功能

    给员工涨工资,当涨后的薪水超过6000块前时候,审计员工的信息。

    /*创建表,用于保存审计信息*/

    create table audit_info

    (

        information varchar2(200)

    );

    create or replace trigegr do_audit_emp_salary

    after update

    on emp

    for each row

    begin 

        /*当涨后的薪水大于6000,插入审计信息*/

        if :new.sal > 6000 then 

           insert into audit_info_values(:new.empno||'   '||:new.ename||'   '||:new.sal);

        end if;

    end;

    0赞 · 0采集
  • 慕设计4302654 2021-11-09

    触发器案例二:数据确认

    涨工资不能越长越少

     /*

    涨后的薪水 , 涨前的薪水都是对同一条数据进行操作,需要使用到行级触发器

    :old和:new    代表同一条记录

    :old    表示操作改行之前,这一行的值

    :new   表示操作改行之后,这一行的值

    */


    create or repalce trigger checksalary

    before update

    on emp 

    for each row

    begin

        /*if    涨后的薪水 < 涨前的薪水 then */

            if   :new.sal< :old.sal then

               raise_application_error(-20002,'涨后的薪水不能小于涨前的薪水. 涨后的薪水:'||:new.sal||'  涨前的薪水:'||:old.sal);

            end if;

    end;

    http://img3.mukewang.com/6189df570001213406920192.jpg

    0赞 · 1采集
  • 慕设计4302654 2021-11-09

    触发器案例一:复杂的安全性检查

    禁止在非工作时间插入新员工

    非工作时间:

    /*

    周末:to_char(sysdate,'day') in('星期六','星期日')

    上班前、下班后:to_number(to_char(sysdate,'hh24')) not between 8 and 18

    */

    select to_char(sysdate,'day') 周,to_number(to_char(sysdate,'hh24')) 小时 ,sysdate from dual;

    http://img3.mukewang.com/6189db10000166bd05710106.jpg


    Create or repalce trigger securityemp

    before insert /*在插入语句之前执行PLSQL语句*/

    on emp

    declare/*程序中不需要使用变量的话 ,可省略不写*/

    begin

        if to_char(sysdate,'day') in('星期六','星期日') or 

           to_number(to_char(sysdate,'hh24')) not between 8 and 18 then

            /*禁止insert新员工,Oracle错误的区间代码自定义-20000到-20999*/

           raise_application_error(-20001,'禁止在非工作时间插入新员工');

        end if;

    end;    

    0赞 · 0采集
  • 慕设计4302654 2021-11-05

    创建触发器的语法:

        

        有FOR EACH ROW 就表明是行级触发器,没有则是语句级触发器

    触发器的类型:

        语句级触发器:针对是表

    行级触发器:针对是行

    0赞 · 0采集
  • 慕设计4302654 2021-11-04

    触发器的定义

        是一个与表相关联的、存储的PL/SQL程序。

    触发器的作用

        每当一个特定的数据操作欲绝(insert、update、delete)在指定的表上发出时,Oracle自动地执行触发器中定义的语句序列。

    创建触发器[在员工表中插入一条记录,打印“成功插入新员工”这句话]

        create trigger saynewemp

        after insert

        on emp

        declare

        begin

            dbms_output.put_line('成功插入新员工');

        end;

        /

    0赞 · 1采集
  • 慕设计4302654 2021-11-04

    触发器的应用场景

        1.复杂的安全性检查

        2.数据确认

        3.实现审计功能

        4.数据备份和同步

    触发器的分类

        语句级触发器和行级触发器

        

    0赞 · 0采集
  • 慕斯卡6169147 2020-12-03

    :old  与 :new 的用法

    截图
    0赞 · 0采集
  • 慕斯卡6169147 2020-12-02

    create or replace trigger trg

    before/after

    delete/insert/update(of 列)

    on table

    for each row(where 条件) --行级触发器 触发语句作用的每一条记录都被触发。 使用:old和:new伪记录变量,识别值的状态。

    plsql块

    截图
    0赞 · 0采集
  • 慕斯卡6169147 2020-12-02

    触发器的具体应用场景: 

    • 复杂的安全性检查

      • 禁止在非工作时间添加员工(周末、9~17之外的时间),使用语句级触发器

    • 数据的确认:比如涨工资不能长成负的

    • 数据库审计:类似于操作日志

    • 数据的备份和同步:主从数据同步


    截图
    0赞 · 0采集
  • 慕斯卡6169147 2020-12-02
    create trigger add_new_emp
        after insert on emp
     declare
     
     begin
         dbms_output.puline('成功插入新员工');
     end;
     /
    0赞 · 0采集
  • 宗强666 2020-10-12

    课程总结:触发器的应用场景。

    截图
    0赞 · 0采集
  • 宗强666 2020-10-12

    数据的备份和同步。触发器是同步备份,没有延迟。快照是异步备份。

    截图
    0赞 · 0采集
  • 宗强666 2020-10-12

    快速建立备份表

    截图
    0赞 · 0采集
  • 宗强666 2020-10-12

    数据审计:当数据大于指定值时,插入审计信息

    截图
    0赞 · 0采集
  • 宗强666 2020-10-12

    数据的确认

    截图
    0赞 · 0采集
  • ciicjsb 2020-08-27

    222222222

    截图
    0赞 · 0采集
  • ciicjsb 2020-08-27

    111111111111

    截图
    0赞 · 0采集
  • zycsyd 2020-07-31

    create or replace trigger trg

    after update

    on table

    for each row

    begin

    update table_bak set sal=:new.sal where empno=:new.empno

    end;

    /

    0赞 · 0采集
  • zycsyd 2020-07-31

    create or replace trigger trg

    after update

    on table

    for each row

    begin

    if :new.sal>6000 then

    insert into table1 values();

    end if;

    end;

    /

    0赞 · 0采集
  • zycsyd 2020-07-31

    create or replace trigger trg

    before update

    on table

    for each row

    begin

    if :new.sal<:old.sal then

    raise_application_error(-20002,'降薪?');

    end if;

    end;

    /

    0赞 · 0采集
  • zycsyd 2020-07-31

    周末:to_char(sysdate,'day') in('星期六','星期日')

    非上班时间:to_number(to_char(sysdate,'hh24')) not between 9 and 18

    create or replace trigger trg

    before insert 

    on table

    begin

     if to_char(sysdate,'day') in('星期六','星期日' or to_number(to_char(sysdate,'hh24')) between 9 and 18 then

    raise_application_error(-20001,'加毛线班')

    end if;

    end;

    /

    1赞 · 1采集
  • zycsyd 2020-07-31

    create or replace trigger trg

    before/after

    delete/insert/update(of 列)

    on table

    for each row(where 条件) --行级触发器 触发语句作用的每一条记录都被触发。 使用:old和:new伪记录变量,识别值的状态。

    plsql块

    1赞 · 0采集
  • Noidea_0 2020-06-30

    创建触发器的语法

    截图
    0赞 · 0采集
  • 小弟阿威 2020-06-08

    创建一个触发器trigger

    http://img4.mukewang.com/5edd6603000131c006650503.jpg

    0赞 · 0采集
数据加载中...
开始学习 免费