日期:2014-05-16  浏览次数:20486 次

Oracle 主键自增长

Table:

CREATE TABLE TEST_A
    (
        ID NUMBER NOT NULL,
        NAME CHAR(200),
        ADDRESS CHAR(200),
        CONSTRAINT ID PRIMARY KEY (ID)
    )

?

Sequence:

create sequence S_TEST_A
minvalue 1
maxvalue 9999999999999999999999999999
start with 21
increment by 1
cache 20;

?

Trigger:

create or replace trigger "test_a_trigger" before
insert on TEST_A for each row 
when (new.id is null)
begin
     select S_TEST_A.nextval into:new.id from dual;
end;

??

?