当前位置:网站首页>Oracle 序列+触发器
Oracle 序列+触发器
2022-07-01 05:41:00 【WHY-small】
Oracle 序列+触发器
删除序列
DROP IAM_USER_PUSH_ID_SEQ;
添加序列
CREATE SEQUENCE "IAM_USER_PUSH_ID_SEQ" INCREMENT BY 1 MINVALUE 1 MAXVALUE 999999999999999999999999 CYCLE NOCACHE ORDER ;
触发器 -简单
create or replace trigger IAM_USER_PUSH_ID_TRI
before insert on IAM_USER_PUSH
for each row
begin
select IAM_USER_PUSH_ID_SEQ.nextval into :new.id from dual;
end;
触发器-如果存在会替换
CREATE OR REPLACE TRIGGER "IAM_USER_PUSH_ID_TRI" BEFORE INSERT OR UPDATE ON IAM_USER_PUSH
FOR EACH ROW
DECLARE
v_count NUMBER(24) :=0;
v_newVal NUMBER(24) := 0;
BEGIN
IF INSERTING AND :new.id IS NULL THEN
SELECT IAM_USER_PUSH_ID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
-- If this is the first time this table have been inserted into (sequence == 1)
SELECT COUNT(1) INTO v_count FROM IAM_USER_PUSH WHERE ID = v_newVal;
IF(v_count <> 0) THEN
LOOP
EXIT WHEN v_count = 0;
SELECT IAM_USER_PUSH_ID_SEQ.nextval INTO v_newVal FROM dual;
SELECT COUNT(1) INTO v_count FROM IAM_USER_PUSH WHERE ID = v_newVal;
END LOOP;
END IF;
-- assign the value from the sequence to emulate the identity column
:new.id := v_newVal;
END IF;
END;
边栏推荐
- 数据库连接池的简单实现
- 【考研高数 自用】高数第一章基础阶段思维导图
- Ssm+mysql second-hand trading website (thesis + source code access link)
- Summary of common components of applet
- Data governance: data governance management (Part V)
- 加密狗资料搜集
- Data governance: data governance framework (Part I)
- Learn the customization and testing of fpga---ram IP from the bottom structure
- 2022.6.30-----leetcode. one thousand one hundred and seventy-five
- idea启动查看项目端口
猜你喜欢
Chapitre d'apprentissage mongodb: Introduction à la première leçon après l'installation
A little assistant for teenagers' physiological health knowledge based on wechat applet (free source code + project introduction + operation introduction + operation screenshot + Thesis)
亲爱的派盘用户,我要向您表白!
[QT] QT after addition, subtraction, multiplication and division, two decimal places are reserved
Boot + jsp University Community Management System (with source Download Link)
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
Qt编写自定义控件-自绘电池
Unity project experience summary
Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
π盘,让您电脑变成个人的私有云
随机推荐
Leetcode top 100 question 2 Add two numbers
云盘里资料被和谐了,怎么办?
Qt编写自定义控件-自绘电池
数据治理:数据治理管理(第五篇)
Series of improving enterprise product delivery efficiency (1) -- one click installation and upgrade of enterprise applications
4GB大文件,如何实时远程传输和共享?
这才是大学生必备软件 | 知识管理
Xuanyi maintenance manual
Wild melon or split melon?
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
HCM 初学 ( 一 ) - 简介
【QT】qt加减乘除之后,保留小数点后两位
What things you didn't understand when you were a child and didn't understand until you grew up?
Data governance: data governance framework (Part I)
Data governance: metadata management implementation (Part IV)
Advanced cross platform application development (III): online resource upgrade / hot update with uni app
如何添加葫芦儿派盘
QT waiting box production
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation