create or replace function get_projectcode(p_id number) return varchar2
as
--流程控制用来生成调单的流水号,形如20060112-0001
p_str varchar2(2000);
p_out varchar2(2000);
begin
  select to_char(A_STARTDATE,'yyyy')||to_char(A_STARTDATE,'Q') into p_str from project where projectid = p_id;
  begin
    select to_char(max(to_number(projectcode)+1)) into p_out from project where instr(projectcode,p_str) = 1;
  exception
    when OTHERS then
      p_out := null;
  end;
  if p_out is null then
     p_out := p_str ||'0001';
  end if;
  return p_out;
exception
  when OTHERS then
    return null;
end get_projectcode;
大家看上面的程序,我的本意是想"生成调单的流水号,形如20060112-0001"
可结果老是生成了形如20060112 的,我现在想形成20060112-0001; 后面的####的转换方式我想这样:我在库里面有个季节 workday   这个字段,当先中第一季度时候形成形如20060112-0001,第二季度时候形成形如20060112-0002 依次类推.我不讳写这程序.求大家帮我该下上面的程序  !!! 求你们了 ,我真的急用.

解决方案 »

  1.   

    我的方法不行吗?我已经回了 ...http://community.csdn.net/Expert/topic/5758/5758656.xml?temp=.8406793
      

  2.   

    -- Create sequence 
    create sequence test_SEQ
    minvalue 0
    maxvalue 99999999999999
    start with 1
    increment by 1
    nocache;CREATE OR REPLACE FUNCTION create_SERIAL (p_prefix in varchar2)
    RETURN VARCHAR2 IS
      RESULT VARCHAR2(15);
    BEGIN
      SELECT p_prefix||'-'||  
             TO_CHAR(test_SEQ.NEXTVAL, 'fm0000')
             INTO RESULT
             FROM DUAL;
      RETURN(RESULT);
    END create_SERIAL;select create_SERIAL('20060112') from dual;