当前位置:网站首页>Oracle 字段自增
Oracle 字段自增
2022-08-09 18:45:00 【Please Sit Down】
一、创建表
--创建student表
create table student(
id number not null, --学生id
name varchar2(20) not null --学生姓名
);二、创建序列
create sequence student_id_seq; --创建序列三、测试(向表中添加数据)
insert into student values (student_id_seq.nextval,'张三');
insert into student values (student_id_seq.nextval,'李四');
select * from student; --查询表四、使用触发器创建自增字段
create or replace trigger student_auto_incr
before insert on student --before:执行DML等操作之前触发
for each row --行级触发器
begin
select student_id_seq.nextval into :new.id from dual;
end;
/触发时机:
before:能够防止某些错误操作发生而便于回滚或实现某些业务规则,适用于实现自增字段;
after:在DML等操作发生之后发生,这种方式便于记录该操作或做某些事后处理信息;
instead of:触发器为替代触发器。
五、测试
insert into student(name) values ('张三');
insert into student (name) values ('李四');
select * from student;边栏推荐
猜你喜欢

ebook download | "Business executives' IT strategy guide - why enterprises should implement DevOps"

poj 1182 食物链(带权并查集)

听音识情绪 | 程序员手把手教你搭建神经网络,更快get女朋友情绪,求生欲max!

Openharmony Lightweight System Experiment--GPIO Lighting

嵌入式开发:使用FILL提高代码完整性

基于SSM实现手机销售商城系统

鹅厂机器狗花式穿越10m梅花桩:前空翻、单桩跳、起身作揖...全程不打一个趔趄...

『百日百题 · 基础篇』备战面试,坚持刷题 第五话——循环语句(2)!

新出现的去中心化科学能够为科学领域带来什么?

MQTT X Web:在线的 MQTT 5.0 客户端工具
随机推荐
看完这波 Android 面试题;助你斩获心中 offer
How to suppress alarm storms?
php安装make出现“collect2:error:ldreturned1exitstatus
2022.08.08_每日一题
渗透测试——CFS三层靶机内网渗透实操
Bi Sheng Compiler Optimization: Lazy Code Motion
超多AI开发者等你来玩转,一起燃动昇腾AI创享日南京站!
competed中访问ref为undefined
智驾科技完成C1轮融资,此前2轮已融4.5亿元
优秀的 Verilog/FPGA开源项目介绍(三十一)- OFDM
uniapp离线推送华为厂商申请流程
渗透测试-对新型内存马webshell的研究
CreateCompatibleDC用法
一图详解沃土云创计划高校教师参与全流程
[免费专栏] Android安全之和平精英(FZ)APK逆向分析
[免费专栏] Android安全之Android应用的汉化功能(修改so中的字符串内容)
【分享】入驻集简云开发者平台,如何使用Session Auth配置授权?
Samsung's flagship discount is 1,800, Apple's discount is over 1,000, and the domestic flagship is only reduced by 500 to send beggars
laravel 时区问题timezone
ebook下载 | 《 企业高管IT战略指南——企业为何要落地DevOps》