我想实现表记录数的自增长,按网上写的方法用的是
create table example(
id number(4) not null primary key,
name varchar2(25),
phone varchar2(10),
address varchar2(50)
);--然后需要自定义一个sequence
create sequence emp_sequence
increment by 1 --每次加几个
start with 1 --从1开始计数
nomaxvalue --不设置最大值
nocycle --一直累加,不循环
nocache --不建缓冲区 --有个表和序列还需要一个触发器
create or replace trigger emp_trigger before
insert on example for each row when(new.id is null)
begin
select emp_sequence.nextval into:new.id from dual;
end;但是这样不就是要每写一张表就要定义一个sequence和一个触发器?感觉好麻烦啊
create table example(
id number(4) not null primary key,
name varchar2(25),
phone varchar2(10),
address varchar2(50)
);--然后需要自定义一个sequence
create sequence emp_sequence
increment by 1 --每次加几个
start with 1 --从1开始计数
nomaxvalue --不设置最大值
nocycle --一直累加,不循环
nocache --不建缓冲区 --有个表和序列还需要一个触发器
create or replace trigger emp_trigger before
insert on example for each row when(new.id is null)
begin
select emp_sequence.nextval into:new.id from dual;
end;但是这样不就是要每写一张表就要定义一个sequence和一个触发器?感觉好麻烦啊
解决方案 »
- 初级问题:PL/SQL中过程和函数能够传入变长数组吗?
- 请教一个数据库查询优化的问题
- 如何在存储过程中使用spool??
- 为什么ORCALE不可以将常量做字段
- 急急急急……!请教学过VB、VBA和ORACLE的高手们
- 如果获取一个英文字符的下一个字符,如d的下一个字符为e
- 大家给我解释解释这select语句中 /*+ first_row */是什么意思!!!!!!
- 100分求解,复杂数据库同步问题
- 急!!!!!!!!!!!!!SQL语句
- imp 导入dmp文件 提示ORA-00001: 违反唯一约束条件 (HR.EMP_EMAIL_UK)
- 有这么个变态需求,能否用一句SQL实现
- 一道子查询的题目
SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY CYCLE_FLAG ORDER_FLAG CACHE_SIZE Last
BLOG_BLOG_SEQUENCE 1 1E28 1 N N 0 10
...
都是创建过的一些sequences然后..不明白
2. insert into example(id) values (select max(id) +1 from example)。这样也能实现自动增长。