当前位置:网站首页>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 .
边栏推荐
- Huawei fast game failed to call the login interface, and returned error code -1
- Database recovery strategy
- datagrid直接编辑保存“设计缺陷”
- Microservice link risk analysis
- Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
- Oracle HugePages没有被使用导致服务器很卡的解决方法
- DBeaver同时执行多条insert into报错处理
- Livelocks and deadlocks of concurrency control
- Server optimization of performance tuning methodology
- Oracle checkpoint queue - Analysis of the principle of instance crash recovery
猜你喜欢
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Shell script, awk uses if, for process control
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
装饰器学习01
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
Server optimization of performance tuning methodology
Huawei fast game failed to call the login interface, and returned error code -1
[Yugong series] go teaching course in July 2022 004 go code Notes
MMAP学习
Emotional analysis of wechat chat records on Valentine's day based on Text Mining
随机推荐
NET中小型企业项目开发框架系列(一个)
Detailed explanation of memset() function usage
Business learning of mall commodity module
MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器
微服务链路风险分析
Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
Drawing HSV color wheel with MATLAB
Concurrency control of performance tuning methodology
matlab绘制hsv色轮图
Bitbucket installation configuration
Three components of openpyxl
854. 相似度为 K 的字符串 BFS
Deeply convinced plan X - network protocol basic DNS
Poj 3237 Tree (Tree Chain Split)
Form artifact
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Efficiency difference between row first and column first traversal of mat data types in opencv
Basic grammar of interview (Part 1)
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
如何開發引入小程序插件