日期:2014-05-17 浏览次数:20855 次
create or replace trigger triname before insert on table_name for each row declare num number; begin select seq_name.nextval into num from dual; :new.col := to_char(trunc(sysdate), 'yyyymmdd') ||'-'|| lpad(num, 5, '0'); end triname;
------解决方案--------------------
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>