Oracle ID 自增
实现Oracle Id自增
1、方法一(Oracle Version Oracle 12c版本支持)
create table app_student
(
id integer generated by default as identity
not null primary key,
createtime DATE not NULL
);
insert into app_student(createtime) values(sysdate);
2. 方法二 创建序列
创建表
CREATE TABLE APP_USER(
ID number(20) NOT NULL PRIMARY KEY,
Create_Time date NOT NULL );
--创建序列
create sequence seq_app_user
minvalue 1000
nomaxvalue
start with 1000
increment by 1
nocycle --一直累加,不循环
--nocache --不缓存
cache 10; --缓存10条
创建触发器
--创建触发器,如果insert语句不知道ID自动插入增长值
CREATE OR REPLACE TRIGGER tr_app_user
BEFORE INSERT ON app_user FOR EACH ROW When (new.ID is null)
begin
select seq_app_user.nextval into:new.ID from dual;
end;
插入数据:
ID的格式由序列控制
insert into APP_USER( Create_Time)
values( sysdate)
自己控制ID的格式
insert into APP_USER( ID, Create_Time)
values(to_number(to_char(sysdate,'yyyymmddhh24miss') + seq_app_student.nextval), sysdate)
id的格式为时间+序列
Oracle ID 自增的更多相关文章
- hibernate解决oracle的id自增?
以前做SSH项目时,涉及到的数据库是mySQL,只需将bean的配置文件id设为native 就可以实现表id的自增. 现在用到了Oracle,当然知道这样是不行的啦,那么用序列自增? 我在网络上搜索 ...
- Oracle中用序列和触发器实现ID自增
在设计数据库的时候,Oracle中没有类似SQL Server中系统自动分配ID作为主键的功能,这时Oracle可以通过“序列”和“触发器”来实现ID自动增加的功能. 1.创建序列Sequence c ...
- Oracle 通过触发器实现ID自增
Oracle不像Mysql,SQLServer能够直接设置ID自增,但是可以通过触发器实现ID自增. 1 创建测试表 create table t_goods(id number primary ke ...
- oracle实现自增id
--oracle实现自增id --创建一张T_StudentInfo表 create table T_StudentInfo ( "id" integer not null pri ...
- Oracle 给表添加主键和使ID自增、触发器、创建结构一样的表
1.关于主键:在建表时指定primary key字句即可:create table test( id number(6) primary key, name varchar2(30));如果是对于已经 ...
- Oracle列自增-12c
在ORACLE 12C以前的版本中,如果要实现列自增长,需要通过序列+触发器实现,到了12C ORACLE 引进了Identity Columns新特性,从而实现了列自增长功能. 一.Identity ...
- Oracle列自增实现(2)-Identity Columns in Oracle Database 12c Release 1 (12.1)
Oracle列自增-Identity Columns in Oracle Database 12c Release 1 (12.1) 在ORACLE 12C以前的版本中,如果要实现列自增长,需要通过序 ...
- oracle列自增实现(1)-Sequence+Trigger实现Oracle列自增
Sequence+Trigger实现Oracle列自增 序列的语法格式为: CREATE SEQUENCE 序列名 [INCREMENT BY n] [START WITH n] [{MAXVALUE ...
- oracle 字段自增 两段代码搞定
(这几天做了个小小课程设计时用的是oracle数据库,第一次用,发现oracle和我们以前用的sql server .mysql是有如此多不同的地方,下面是遇到的问题之一和解决方法,和大家分享下) 用 ...
随机推荐
- this 指向问题, 三个例子
'use strict'; var a = 20; function foo () { var a = 1; var obj = { a: 10, c: this.a + 20, fn: functi ...
- git 实现提交远程分支步骤
git clone git branch [分支名] 创建分支 git branch 查看本地所有分支 git checkout [分支名称] 切换分支 ---写代码--- git status (查 ...
- 2018年3月最新的Ubuntu 16.04.4漏洞提权代码
2018年3月最新的Ubuntu 16.04.4漏洞提权代码,本代码取自Vitaly Nikolenko的推子 亲测阿里云提权可用. /* * Ubuntu 16.04.4 kernel priv e ...
- JAVA中将byte[]数组转成16进制字符串
方法一: /** * byte数组转化为16进制字符串 * @param bytes * @return */ public static String byteToHexString(byte[] ...
- quartz 应用
quartz api地址:http://www.quartz-scheduler.org/api/2.2.0/ 根据需求选择quartz调度方案: 1,如果调度时间是固定不变的,可以选择静态调度 2, ...
- jdk安装和环境配置
public class test{ public static void main(String[] args){ System.out.println("hello world" ...
- ORA-15025 搭建DG环境,restore controlfile报错,提示oracle无法使用ASM存储
环境说明: #主库RAC环境 #备库RAC环境,操作系统AIX 6.1 数据库版本11.2.0.3 报错说明: #主库备份控制文件,传输至备库,备库restore 报错 本篇文档,分为两大阶段:第一阶 ...
- linux管道命令之head与tail
常常会遇到这样的情况: 1.我训练一个模型需要用到很多图片,这些图片都在一个文件夹下面,但是我想仅仅拷贝个一两张看一下图片的质量怎么样? 2.文件夹下有各种各样的数据,数目非常庞大,我想看一下文件夹下 ...
- LAMP搭建个人网站
最近发了一篇paper,需要把成果展示出来,想到正好想到自己有一个阿里云服务器,并且在万网上看到www.yongjieshi.com这个域名一年才50块钱,于是决定搭建一个自己的网站 如果linux玩 ...
- [LeetCode&Python] Problem 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...