oracle沒有ORACLE自增字段這樣的功能,但是通過觸發(fā)器( trigger )和序列( sequence )可以實(shí)現(xiàn)。 create table t_client (id number(4) primary key , pid number(4) not null , name varchar2(30) not null , client_id varchar2(10), client_level char (3), bank_acct_no varchar2(30), contact_tel varchar2(30), address varchar2(30), zip_code varchar2(10), is_leaf char (1) default 'y' check (is_leaf in ( 'y' , 'n' )), is_client char (1) default 'n' check (is_client in ( 'y' , 'n' ) )); 假設(shè)關(guān)鍵字段為id,建一個(gè)序列,代碼為: create sequence seq_t_client_id minvalue 1 maxvalue 99999999 start with 1 increment by 1 nocache order ; 建解發(fā)器代碼為: CREATE OR REPLACE TRIGGER trg_t_client_id BEFORE INSERT ON t_client FOR EACH ROW BEGIN SELECT seq_t_client_id.nextval INTO :new.id FROM dual; END ; / |
聯(lián)系客服