要实现生成一个6位数的数字第一位是年份后面5位是递增数字从00001开始,怎么办?如今年是03年,生成第一个为300001,第二个为30002....
先创sequence:
create sequence seq_ticket_code increment by 1 start with 100001 maxvalue 99999999 cycle;
再创函数:
create or replace function sf_GetTicketCode return number
is
ticket_code number(10);
--ticket_seq number(10);
--ticket_year number(1);
begin
select to_number(to_char(sysdate,'y'))||substr(to_char(seq_ticket_code.nextval),2,5)
into ticket_code from dual;
return ticket_code;
exception
when others then
return null;
end;
////
SQL> select sf_GetTicketCode from dual;
SF_GETTICKETCODE
----------------
300010