1 创建表

/*第一步:创建表格*/
create table t_user(
id int primary key, --主键,自增长
username varchar(20),
password varchar(20),
type varchar(20)
);

2 创建自增序列信息

/*第二步:建立自定义的sequence*/
CREATE SEQUENCE user_sequence
increment by 1 -- 每次加几个
start with 1 -- 从1开始计数
nomaxvalue -- 不设置最大值
nocycle -- 一直累加,不循环
nocache -- 不建缓冲区

3 建立触发器

/*第三步:建立触发器*/
create trigger mem_trig before
insert on t_user for each row when (new.id is null)
begin select user_sequence.nextval into:new.id from dual; end;

4 添加数据

/*第四步:插入数据*/
insert into t_user values(null,'aaa','aaa','admin');
insert into t_user values(null,'bbb','bbb','user');
insert into t_user values(null,'ccc','ccc','admin');
insert into t_user values(null,'ddd','ddd','user');

获取插入的自增id

select reg_form.currval from dual

  

oracle 主键自增并获取自增id的更多相关文章

  1. oracle主键自增

    oracle主键自增 1建立数据表 create table Test_Increase(            userid number(10) primary key,  /*主键,自动增加*/ ...

  2. oracle 主键自增 设置----杜恩德

    <div id="topicList"> <div class="forFlow"> <div class = "pos ...

  3. oracle 主键应用序列和触发器实现自动增长

    oracle 主键自动增长 这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create table simon_example ( id number(4) not null pr ...

  4. oracle 主键自动增长

    oracle 主键自动增长 2009-12-11 16:07:00|  分类: 数据库资料|字号 订阅     这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create tabl ...

  5. Oracle主键异常处理

    Hibernate: insert into test1.WarnWeather (WAREA, wdate, WDAYS, WINFO, WTYPE, WNO) values (?, ?, ?, ? ...

  6. oracle主键修改&设置某一字段可以为null

    1.oracle主键修改 1.1)首先查看需要修改的表的主键名,默认的情况下,数据库会自动分配 select * from user_cons_columns where table_name='表名 ...

  7. Oracle 主键、联合主键的查询与创建

    --查询某个表是否有唯一主键 select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = ...

  8. MySQL与Oracle主键Query性能测试结果

    测试结果总结如下: 1. 按主键读:SQL形式:SELECT * FROM table WHERE id=?. 1.1. 主键为数字.如果所有ID均不存在,纯比较SQL解析能力.MySQL解析SQL的 ...

  9. 08Mybatis_入门程序——增加用户的操作以及返回自增主键的功能以及返回非自增主键的功能

    本文要实现的功能是:给user表增加一个用户. 建表如下:

随机推荐

  1. Java中创建String的两种方式

    1.在Java中,创建一个字符串有两种方式 String x = "abc";String y = new String("abc"); 这两种方式有什么区别呢 ...

  2. 02 body标签中的相关标签

    今日内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  3. SpringMVC中mvc:view-controller的使用

    1.重定向 <mvc:view-controller path="/" view-name="redirect:/admin/index"/> 即如 ...

  4. 【漏洞学习】slowHTTPtest 慢速 DOS 攻击方法 修复方案

    日期:2018-05-28 21:41:59 更新:2019-07-05 23:15:21 作者:Bay0net 介绍:学习一下 slowHTTPtest 的攻击及防御. 0x01. 安装 下载链接 ...

  5. 系统分析与设计HW1

    软件工程的定义 1993年,电气电子工程师学会(IEEE)给出了一个定义:"将系统化的.规范的.可度量的方法用于软件的开发.运行和维护的过程,即将工程化应用于软件开发中". 阅读经 ...

  6. Python学习之==>文件操作

    1.打开文件的模式 r,只读模式(默认)[不可写:文件不存在,会报错] w,只写模式[不可读:不存在则创建:存在则删除内容] a,追加模式[不可读:不存在则创建:存在则追加内容] r+,读写模式[可读 ...

  7. Python实现比较两个列表(list)范围

    Python实现比较两个列表(list)范围 有一道题: 比较两个列表范围,如果包含的话,返回TRUE,否则FALSE. 详细题目如下: Create a function, this functio ...

  8. nginx详解反向代理,负载均衡,LNMP架构上线动态网站

    1.nginx介绍 nginx.org Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为“engine X”,是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/ ...

  9. 使用 go protoc --go_out 输出的 *.pb.go文件时报 undefined: proto.ProtoPackageIsVersion3

    事情是这样的:我参考go的 grpc 实现 https://grpc.io/docs/quickstart/go/ Download the example The grpc code that wa ...

  10. Eclipse 添加 UML Model插件

    1.下载安装 ModelGson 下载链接:https://pan.baidu.com/s/1smIZApv   密码:mu5l eclipse安装ModelGson(注意不用解压ModelGson, ...