当前位置:网站首页>Oracle sequence + trigger
Oracle sequence + trigger
2022-07-01 05:50:00 【WHY-small】
Oracle Sequence + trigger
Delete sequence
DROP IAM_USER_PUSH_ID_SEQ;
Add sequence
CREATE SEQUENCE "IAM_USER_PUSH_ID_SEQ" INCREMENT BY 1 MINVALUE 1 MAXVALUE 999999999999999999999999 CYCLE NOCACHE ORDER ;
trigger - Simple
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;
trigger - Replace if present
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;
边栏推荐
- Excel dynamic chart
- Vscode function annotation / file header annotation shortcut
- Codeforces Round #803 (Div. 2)vp
- 表格中el-tooltip 实现换行展示
- 基于LabVIEW的计时器
- Call us special providers of personal cloud services for College Students
- Primary application case of Excel DuPont analyzer
- OpenGL es: (1) origin of OpenGL es (transfer)
- Summary of common components of applet
- Retention rate of SQL required questions
猜你喜欢

Huluer app help

Scope data export mat

My experience from technology to product manager

Brief description of activation function

OpenGL es: (5) basic concepts of OpenGL, the process of OpenGL es generating pictures on the screen, and OpenGL pipeline

skywalking集成nacos动态配置

【笔记】电商订单数据分析实战

C language beginner level - realize the minesweeping game

linux 关闭redis 进程 systemd+

Educational administration management system (free source code)
随机推荐
My experience from technology to product manager
tese_Time_2h
【考研高数 自用】高数第一章基础阶段思维导图
Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project
uniapp树形层级选择器
Educational administration management system (free source code)
SystemVerilog学习-06-类的封装
SystemVerilog学习-09-进程间同步、通信和虚方法
穿越派·派盘 + Mountain Duck = 数据本地管理
OpenGL es: (1) origin of OpenGL es (transfer)
Qt编写自定义控件-自绘电池
从诺奖知“边缘计算”的未来!
Codeforces Round #803 (Div. 2)vp
SSM的教务管理系统(免费源码获取)
json数据比较器
论文学习记录随笔 多标签之LIFT
Beauty of Mathematics - Application of Mathematics
Through cooperation with the University of international trade, we can increase efficiency for college students
2022.6.30-----leetcode. one thousand one hundred and seventy-five
idea启动查看项目端口