当前位置:网站首页>Oracle triggers
Oracle triggers
2022-07-05 22:02:00 【The sea of waves】
Oracle trigger
Trigger application scenarios

Create trigger
create trigger saynewemp
after insert
on emp
declare
begin
dbms_output.put_line(" Successful insertion of new employees ");
end;
grammar

type
- Statement level triggers
Execute once before or after the operation of the specified action statement , No matter how many lines this statement affects .
- Line level triggers
Every record that triggers a statement is triggered . Use... In row level triggers :old and :new Pseudo record variables , Identify the status of the value .
application
Application scenarios 1: Implement complex security checks ( It is forbidden to insert new employees during non working hours )
/*
1. Over the weekend : to_char(sysdate,'day') in (' Saturday , Sunday ')
2. Before going to work , After work to_number( to_char(sysdate,'hh24')) not beween 9 and 18
*/
create or replace trigger securityemp
before insert
on emp
begin
if to_char(sysdate,'day') in (' Saturday ',' Sunday ') or
to_number(to_char(sysdate,'hh24')) not between 9 and 18 then
-- It is forbidden to insert new employees
raise_application_error(-20001,' It is forbidden to insert new employees during non working hours ');
end if;
end;
Application scenarios 2: Pay rise cannot be less and less
/*
:old and :new Represents the same record
:old Indicates before the operation of this line , The value of this line
: new Indicates that after the operation of this line , The value of this line
*/
create or replace trigger checksalary
before update
on emp
for each row
begin
-- if The salary after the increase < Salary before increase then
if :new.sal < :old.sal then
raise_application_error(-20002,' The salary after the rise cannot be less than the salary before the rise , The salary after the increase :'|| :new.sal || ' Salary before increase :' :old.sal );
end if;
end;
Application scenarios 3: When the salary increases more than 6000 Block time , Audit the employee's information
create or replace trigger do_auid_emp_salary
after update
on emp
for each row
begin
-- When the salary is higher than 6000, Insert audit information
if :new.sal > 6000 then
insert into audit_info values(:new.empno || '' ||:new.ename|| '' ||:new.sal);
end if;
end;
Application scenarios 4: Database backup and synchronization
create or replace trigger sync_salary
after update
on emp
for each row
begin
-- When the master table is updated . Update the backup table by yourself
update emp_back set sal=:new.sal where empno=:new.empno;
end;
/
There is something wrong , Welcome to the discussion .
Last , Welcome to pay attention to my wechat , What do you like , Collection , Forwarding is my greatest encouragement .

边栏推荐
- A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
- How to organize an actual attack and defense drill
- 笔记本电脑蓝牙怎么用来连接耳机
- ICMP 介绍
- C language knowledge points link
- Huawei fast game failed to call the login interface, and returned error code -1
- MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
- Blocking of concurrency control
- 科技云报道:算力网络,还需跨越几道坎?
- Poj 3237 Tree (Tree Chain Split)
猜你喜欢

MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server

Livelocks and deadlocks of concurrency control

华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010

深信服X计划-网络协议基础 DNS

Talking about MySQL index

Create a virtual machine on VMware (system not installed)

Scenario interview: ten questions and ten answers about distributed locks

Bitbucket installation configuration

Cold violence -- another perspective of objective function setting

Huawei cloud modelarts text classification - takeout comments
随机推荐
Summary of El and JSTL precautions
Business learning of mall order module
crm创建基于fetch自己的自定义报告
PIP install beatifulsoup4 installation failed
Concurrency control of performance tuning methodology
装饰器学习01
EBS Oracle 11g cloning steps (single node)
The real situation of programmers
Oracle检查点队列–实例崩溃恢复原理剖析
Codeforces 12D Ball 树形阵列模拟3排序元素
初级软件测试必问面试题
Cold violence -- another perspective of objective function setting
QML reported an error expected token ";", expected a qualified name ID
Kingbasees v8r3 data security case - audit record clearing case
Create a virtual machine on VMware (system not installed)
Livelocks and deadlocks of concurrency control
笔记本电脑蓝牙怎么用来连接耳机
DBeaver同时执行多条insert into报错处理
大约SQL现场“这包括”与“包括在”字符串的写法
Net small and medium-sized enterprise project development framework series (one)