当前位置:网站首页>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;
边栏推荐
猜你喜欢

Summary of spanner's paper

How to create a progress bar that changes color according to progress

了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收

Redis数据库的部署及常用命令

Deeply understand the underlying implementation principle of countdownlatch in concurrent programming

喊我们大学生个人云服务特供商

Trust guessing numbers game

云盘里资料被和谐了,怎么办?

Set集合详细讲解

如何创建一个根据进度改变颜色的进度条
随机推荐
LeetCode 最大矩形,最大正方形系列 84. 85. 221. 1277. 1725. (单调栈,动态规划)
Leetcode top 100 questions 1 Sum of two numbers
Codeforces Round #803 (Div. 2)vp
Basic electrician knowledge 100 questions
HCM 初学 ( 四 ) - 时间
JSON data comparer
Xuanyi maintenance manual
运行时候的导包搜索路径虽然pycharm中标红但不影响程序的执行
轩逸保养手册
输入一个表达式(用字符串表示),求这个表达式的值。
导数的左右极限和左右导数的辨析
Data governance: data governance management (Part V)
HDU - 1024 Max Sum Plus Plus(DP)
Unity project experience summary
芯片,建立在沙粒上的帝国!
激活函数简述
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
win10、win11中Elan触摸板滚动方向反转、启动“双指点击打开右键菜单“、“双指滚动“
2022.6.30-----leetcode. one thousand one hundred and seventy-five
boot+jsp的高校社团管理系统(附源码下载链接)