Oracle创建一个这样的字段,格式如:YYYYMMDD-0000X,
YYYYMMDD是当天的年月日,X是自增的数字,起始从0000X开始.
SQL> create table test (id varchar2(20),name varchar2(16));
表已创建。
SQL> create sequence seq_test_id
2 start with 1
3 increment by 1;
序列已创建。
SQL> create or replace trigger trig_test
2 before insert on test
3 for each row
4 declare
5 -- local variables here
6 begin
7 SELECT to_char(SYSDATE,'yyyymmdd')||'-'||lpad(seq_test_id.NEXTVAL,5,'0'
) INTO :new.id FROM dual;
8 end trig_test;
9 /
触发器已创建
SQL> insert into test (name) values ('AC米兰');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from test;
ID NAME
-------------------- ----------------
20100324-00002 AC米兰
SQL>
