ok,look
1)
create sequence stud_seq
start with 1
increment by 1
nomaxvalue;
2)
create table stud(stud_id number,name char(10),sex char(2));
3)
create or replace trigger stud_trigger
before insert on stud
for each row
declare
newstud_id number;
begin
select stud_seq.nextval into newstud_id from dual;
:new.stud_id:=newstud_id;
end;
运行结果
SQL> select * from stud;
STUD_ID NAME SEX
---------- ---------- ---
SQL> insert into stud(name,sex) values('ab','cd');
1 row inserted
SQL> select * from stud;
STUD_ID NAME SEX
---------- ---------- ---
1 ab cd
SQL> insert into stud(name,sex) values('cd','ef');
1 row inserted
SQL> select * from stud;
STUD_ID NAME SEX
---------- ---------- ---
1 ab cd
2 cd ef
SQL>