OracleのID自動インクリメント
–sequenceを作成
create sequence seq_on_test
increment by 1
start with 1
nomaxvalue
nocycle
nocache;
–テーブルを作成
drop table test;
create table test(
ID integer
,stu_name nvarchar2(4)
,stu_age number
);
–データを挿入
insert into test values(seq_on_test.nextval,’Mary’,15);
insert into test values(seq_on_test.nextval,’Tom’,16);
select * from test;
–結果
/*
1 Mary 15
2 Tom 16
*/
–seqの二つ対策
select seq_on_test.currval from dual;
select seq_on_test.nextval from dual;
–結果
/*
2
3
*/