当前位置:网站首页>oracle的触发器的使用举例
oracle的触发器的使用举例
2022-07-27 06:10:00 【hawanglc】
这个文章演示了oracle触发器的使用,以备不时之需
-- 创建一个表,未来需要在这个表上建立触发器
create table baby_test
(id number(20),
name varchar(50),
birthday date,
login_date timestamp
);
-- 创建一个保存触发器操作的表
-- drop table baby_test_log;
create table baby_test_log
(id number(20),
name varchar(50),
insert_date date default sysdate,
operate varchar2(50)
);
-- 创建一个触发器。当对baby_test表的数据插入,修改和删除的时候,向baby_test_log中插入数据
CREATE OR REPLACE TRIGGER trg_baby_test BEFORE
INSERT OR UPDATE or delete ON baby_test
FOR EACH ROW DECLARE
-- local variables here
BEGIN
CASE
WHEN inserting THEN
INSERT INTO baby_test_log (
id,
name,
operate
) VALUES (
:new.id,
:new.name,
'inserting'
);
WHEN updating('name') THEN
INSERT INTO baby_test_log (
id,
name,
operate
) VALUES (
:old.id,
:old.name,
'updating name'
);
WHEN deleting THEN
INSERT INTO baby_test_log (
id,
name,
operate
) VALUES (
:old.id,
:old.name,
'deleting'
);
END CASE;
END;
-- 测试触发器
insert into baby_test
select 1,'baby',to_date('19990101','yyyymmdd'), sysdate from dual;
select * from baby_test;
update baby_test
set name = 'hugh'
where id = 1;
delete from baby_test where id = 1;
-- 查看触发器的结果
select * from baby_test_log;边栏推荐
- Shell系统学习之Shell条件测试,判断语句和运算符
- “蔚来杯“2022牛客暑期多校训练营1
- 端口转发小结
- Internal class -- just read this article~
- Pan Aimin, chairman of instruction set, attended the 2022 ecug con to speak for China's technical forces
- Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较
- Digital image processing Chapter 1 Introduction
- Usage of string class
- 指令集 x 数澜科技丨加速政企数字化转型,打造DT领域独角兽企业联盟
- Oracle database problems
猜你喜欢

Digital image processing -- Chapter 3 gray scale transformation and spatial filtering

Convert Excel to csv/csv UTF-8

Overall dichotomy?

Generics -- learn it, and there are many benefits

ESP8266(ESP-12F) 第三方库使用 -- SparkFun_APDS9960 (手势识别)

李沐动手学深度学习V2-transformer和代码实现

Consideration on how the covariance of Kalman filter affects the tracking effect of deepsort

指令集 x 数澜科技丨加速政企数字化转型,打造DT领域独角兽企业联盟

指令集董事长潘爱民出席2022 ECUG Con,为中国技术力量发声

零号培训平台课程-1、SQL注入基础
随机推荐
What is OKR and what is the difference between OKR and KPI
使用pip命令切换不同的镜像源
Confluence漏洞学习——CVE-2021-26084/85,CVE-2022-26134漏洞复现
A Competitive Swarm Optimizer for Large Scale Optimization
"Weilai Cup" 2022 Niuke summer multi school training camp 1
C# 常用功能整合-3
R2live code learning record (3): radar feature extraction
Golang controls the number of goroutines and obtains processing results
Overall dichotomy?
[Vani has a date] tail on rainy days
MySQL limit paging query optimization practice
Quartus:往别人的工程添加.v文件报错
Codeforces Round #809 (Div. 2)(6/6)(Kruskal重构树)
零号培训平台课程-1、SQL注入基础
pytorch笔记:TD3
请问 mysql timestamp(6) 用flink-sql接过来是 null,这点有办法处理不
用typescript实现排序-递增
Jmeter: interface automation test - BeanShell compares database data and return data
Jest single test style problem [identity obj proxy] NPM package
Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较