当前位置:网站首页>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;
边栏推荐
- rust猜数字游戏
- Multi table operation - foreign key cascade operation
- 千万不要把笔记视频乱放!
- Looking for high school student developers with similar interests
- 码蹄集 - MT3149 · AND - 数据不是很强,暴力剪枝就能骗AC
- 云盘里资料被和谐了,怎么办?
- 2022第八届中国国际“互联网+”大学生创新创业大赛产业命题赛道开启报名!
- Set集合詳細講解
- Rainbow combines neuvector to practice container safety management
- HCM 初学 ( 四 ) - 时间
猜你喜欢

One click deployment of highly available emqx clusters in rainbow

Dynamic verification of new form items in El form; El form verifies that the dynamic form V-IF does not take effect;
![[RootersCTF2019]babyWeb](/img/b4/aa8f8e107a9dacbace72d4717b1834.png)
[RootersCTF2019]babyWeb

芯片,建立在沙粒上的帝国!

HCM 初学 ( 二 ) - 信息类型

Summary of spanner's paper

0xc000007b the application cannot start the solution normally (the pro test is valid)

多表操作-外键级联操作

【医学分割】u2net

C语言初阶——牛客网精选好题
随机推荐
Common solutions for mobile terminals
[SRS] use of Vhost isolated stream: push / pull Stream Address
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
芯片,建立在沙粒上的帝国!
JDBC常见面试题
HDU - 1024 Max Sum Plus Plus(DP)
CentOS 7 installed php7.0 using Yum or up2date
了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
MySQL converts milliseconds to time string
LRU cache for leveldb source code analysis
轩逸保养手册
为什么用葫芦儿派盘取代U盘?
TypeORM 框架
JSON data comparer
Continuous breakthrough and steady progress -- Review and Prospect of cross platform development technology of mobile terminal
Advanced cross platform application development (III): online resource upgrade / hot update with uni app
Ssm+mysql second-hand trading website (thesis + source code access link)
HDU - 1069 Monkey and Banana(DP+LIS)
2022第八届中国国际“互联网+”大学生创新创业大赛产业命题赛道开启报名!
Is it safe for a novice to open a securities account?