1建立数据表

create table Test_Increase(
           userid number(10) primary key,  /*主键,自动增加*/
           username varchar2(20)
           );

2创建自动增长序列

 CREATE SEQUENCE TestIncrease_Sequence
 INCREMENT BY 1   -- 每次加几个  
     START WITH 1     -- 从1开始计数  
     NOMAXVALUE       -- 不设置最大值  
     NOCYCLE          -- 一直累加,不循环  
     CACHE 10; 

3创建触发器

CREATE TRIGGER Test_Increase BEFORE
insert ON  Test_Increase FOR EACH ROW
begin
select TestIncrease_Sequence.nextval into:New.userid from dual; end;

4 提交

commit;

5 测试

反复执行如下语句:

insert into Test_Increase(Username) values('test')

6 查看插入结果:

userid username

1       test

 2       test

 3       test

 4       test

 5       test

 6       test

 7       test

 8       test

 9       test

oracle主键自增的更多相关文章

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

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

  2. oracle 主键自增并获取自增id

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

  3. oracle 主键自增

    将表t_uaer的字段ID设置为自增:(用序列sequence的方法来实现) ----创建表 Create table t_user( Id number(6), userid varchar2(20 ...

  4. Oracle主键自增的实现

    create sequence seq_字段名_表名 minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by ...

  5. for循环往Oracle中插入n条数据,主键自增

    1.主键自增实现方法:http://www.cnblogs.com/Donnnnnn/p/5959871.html 2.for循环往Oracle中插入n条数据 BEGIN .. loop insert ...

  6. 关于oracle设置主键自增的问题

    关于orcale设置主键自增的问题 关于主键Oracle中并没有提供一个直接的语句设置,对于这个oralce一般都是用序列和触发器来实现 一下又两种方法来实现 一 ,不使用触发器 创建序列: crea ...

  7. oracle中主键自增

    oracle中主键自增 下面用一个例子来说明自增主键的创建: 1.建用户数据表 drop table dectuser; create table dectuser( userid integer p ...

  8. 在Oracle中设置主键自增

    转自:https://www.2cto.com/database/201705/636725.html 数据库设置主键自增">oracle数据库设置主键自增: --创建表 create ...

  9. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'portal.hibernate_sequence' doesn't exist, 谈谈主键自增的方式

    最近几天几天做项目用到了Spring Data JPA,确实是个好东西,省了很多力气.但是由于刚开始用,也遇到不少头疼的问题,如下,调用JpaRepository接口的save方法保存一个对象到数据库 ...

随机推荐

  1. 理解 OpenStack + Ceph (5):OpenStack 与 Ceph 之间的集成 [OpenStack Integration with Ceph]

    理解 OpenStack + Ceph 系列文章: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 (5)Ceph 与 OpenS ...

  2. java 知识点随记

    JAVA 读取配置文件: Properties props= new Properties();//文件在src目录下,编译会被加载到classpath下. Props.load(Test.class ...

  3. Flash 二进制传图片到后台Java服务器接收

    需求:把客户端处理过的图片返还给服务器Flash端代码 01 package {02     import com.adobe.images.JPGEncoder;    03     import  ...

  4. GIT安装和使用

    GIT 首先登陆github账号   在本地创建一个文件夹   点击文件夹,右键,选择Git create repository here 操作之后,会生成一个.git文件(这个文件为隐藏文件) 在此 ...

  5. 网络攻防比赛PHP版本WAF

    这次去打HCTF决赛,用了这个自己写的WAF,web基本上没被打,被打的漏洞是文件包含漏洞,这个功能在本人这个waf里确实很是捉急,由于只是简单检测了..和php[35]{0,1},导致比赛由于文件包 ...

  6. DOM操作基础

    ownerDocument 返回元素的 ownerDocumentoffsetParent 获取父节点(找有定位的父节点,没有定位默认是body,ie7以下定位在自己是html)parentNode ...

  7. PhpExcel中文帮助手册|PhpExcel使用方法

    下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...

  8. Nginx1.9.0的安装

    下载文件 http://nginx.org/en/download.html 下载 nginx-1.9.3.tar.gz 安装Nginx 安装 一.安装nginx时必须先安装相应的编译工具 yum - ...

  9. 手写PHP AJAX数据脚本

    <script type="text/javascript"> var xmlrequest = ""; function getXMLreques ...

  10. Solving GitHub FetchHead (MergeConflict) in Visual Studio 2013

    I was getting the error: An error occurred. Detailed message: An error was raised by libgit2. Catego ...