insert into student(student_id,first_name,last_name) values(seq_no.nextval,'','');
查看
1
select * from dba_sequences where sequence_owner='用户名';
删除
1
DROP SEQUENCE seq_no --删除序列
还可以增加触发器,这样就可以不用指定主键的值而自动插入:
触发器名:tri_student_ins
表名:student
列名(主键):student_id
1 2 3 4 5
create trigger tri_student_ins before insert on student for each row when (new.student_id is null) begin select seq_no.nextval into:new.student_id from dual; end;
查看
1
select trigger_name from all_triggers where table_name='XXX';
CREATE OR REPLACE FUNCTION GETMAXNO(NOTYPE in varchar2) RETURN NUMBER AS MaxNo number(18); pragma autonomous_transaction; BEGIN select max_no into MaxNo FROM Sys_MaxNo where NO_TYPE=NOTYPE FOR UPDATE; MaxNo:=MaxNo+1; update Sys_MaxNo set max_no=MaxNo where NO_TYPE=NOTYPE; commit; RETURN MaxNo; exception when no_data_found then begin MaxNo:=1; insert into Sys_MaxNo(no_type,max_no) values(NOTYPE,MaxNo); commit; RETURN MaxNo; end; when others then rollback; END GETMAXNO;
这里的SYS_MAXNO有两个字段:MAX_NO : varchar2NO_TYPE : number