//序列 CREATE SEQUENCE TEST_SEQ START WITH 1 NOMAXVALUE MINVALUE 0 NOCYCLE CACHE 20 NOORDER; //触发器 CREATE OR REPLACE TRIGGER SP_TABLENAME --向表插入ID BEFORE INSERT ON 表名 FOR EACH ROW declare new_id number; begin select TEST_SEQ.nextval into 列名 from dual; :new.列名 := new_id; end;
--建一序列: create sequence seq_name increment by 1 start with 1 maxvalue 99999999999 nocycle cache 10--调用: insert into table(id,name) values(seq_name.nextval, 'name')
create table a(b int, c varchar2(5)); 建一个序列 create sequence a_seq increment by 1 start with 100; 建一个触发器 create or replace trigger t_a before insert on a for each row begin select s_a.nextval into :new.b from dual; end;
能具体点吗
怎样建个序列呀?
CREATE SEQUENCE TEST_SEQ
START WITH 1
NOMAXVALUE
MINVALUE 0
NOCYCLE
CACHE 20
NOORDER;
//触发器
CREATE OR REPLACE TRIGGER SP_TABLENAME --向表插入ID
BEFORE INSERT ON 表名
FOR EACH ROW
declare
new_id number;
begin
select TEST_SEQ.nextval into 列名 from dual;
:new.列名 := new_id;
end;
create sequence seq_name
increment by 1
start with 1
maxvalue 99999999999
nocycle
cache 10--调用:
insert into table(id,name) values(seq_name.nextval, 'name')
建一个序列
create sequence a_seq increment by 1 start with 100;
建一个触发器
create or replace trigger t_a
before insert on a
for each row
begin
select s_a.nextval into :new.b from dual;
end;