1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | --×Ô¶¨ÒåÐòÁÐ create table S_AUTOCODE ( pk1 VARCHAR2(32) primary key, atype VARCHAR2(20) not null, owner VARCHAR2(10) not null, initcycle CHAR(1) not null, cur_sernum VARCHAR2(50) not null, zero_flg VARCHAR(2) not null, sequencestyle VARCHAR2(50), memo VARCHAR2(60) ); -- Add comments to the columns comment on column S_AUTOCODE.pk1 is 'Ö÷¼ü'; comment on column S_AUTOCODE.atype is 'ÐòÁкÅÀàÐÍ'; comment on column S_AUTOCODE.owner is 'ÐòÁкÅËùÓÐÕß'; comment on column S_AUTOCODE.initcycle is 'ÐòÁкŵÝÔö'; comment on column S_AUTOCODE.cur_sernum is 'ÐòÁкÅ'; comment on column S_AUTOCODE.zero_flg is 'ÐòÁкų¤¶È'; comment on column S_AUTOCODE.sequencestyle is 'ÐòÁкÅÑùʽ'; comment on column S_AUTOCODE.memo is '±¸×¢'; -- Create/Recreate indexes create index PK_S_AUTOCODE on S_AUTOCODE (ATYPE, OWNER); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | CREATE OR REPLACE FUNCTION SF_SYS_GEN_AUTOCODE( I_ATYPE IN VARCHAR2, /*ÐòÁÐÀà±ð*/ I_OWNER IN VARCHAR2 /*ÐòÁÐËùÓÐÕß*/ ) RETURN VARCHAR2 IS /**************************************************************************************************/ /* PROCEDURE NAME : SF_SYS_GEN_AUTOCODE */ /* DEVELOPED BY : WANGXF */ /* DESCRIPTION : Ö÷ÒªÓÃÀ´Éú³É×Ô¶¨ÒåµÄÐòÁкŠ*/ /* DEVELOPED DATE : 2016-10-08 */ /* CHECKED BY : */ /* LOAD METHOD : F1-DELETE INSERT */ /**************************************************************************************************/ O_AUTOCODE VARCHAR2(100); /*Êä³öµÄÐòÁкÅ*/ V_INITCYCLE S_AUTOCODE.INITCYCLE%TYPE; /*ÐòÁкŵÝÔö*/ V_CUR_SERNUM S_AUTOCODE.CUR_SERNUM%TYPE; /*ÐòÁкÅ*/ V_ZERO_FLAG S_AUTOCODE.ZERO_FLG%TYPE; /*ÐòÁкų¤¶È*/ V_SEQUENCESTYLE S_AUTOCODE.SEQUENCESTYLE%TYPE;/*ÐòÁкÅÑùʽ*/ V_SEQ_NUM VARCHAR2(100); /*±¾´ÎÐòÁкÅ*/ V_DATE_YEAR CHAR(4); /*Äê·Ý£¬Èç2016*/ V_DATE_YEAR_MONTH CHAR(6); /*Äê·ÝÔ·ݣ¬Èç201610*/ V_DATE_DATE CHAR(8); /*Äê·ÝÔ·ÝÈÕ£¬Èç20161008*/ V_DATE_DATE_ALL CHAR(14); /*ÍêÕûÄê·ÝÐòÁУ¬Èç20161008155732*/ /* Ö§³ÖµÄ²ÎÊýÐòÁУº $YEAR$ --> Äê·Ý $YEAR_MONTH$ --> Äê·Ý+Ô·ݣ¬²»º¬ºº×Ó $DATE$ --> Äê·Ý+Ô·Ý+ÈÕÆÚ£¬²»º¬ºº×Ó $DATE_ALL$ --> ÍêÕûÈÕÆÚ£¬²»º¬ºº×Ó $ORGAPP$ --> ËùÓÐÕß $SER$ --> µ±Ç°ÐòÁкŠ*/ --½â¾ö²éѯÊÂÎñÎÞ·¨Ö´ÐÐDMLµÄÎÊÌâ Pragma Autonomous_Transaction; BEGIN -- ²éѯ¸´ºËÌõ¼þµÄÐòÁкÅÅäÖà SELECT T.INITCYCLE, T.CUR_SERNUM, T.ZERO_FLG, T.SEQUENCESTYLE INTO V_INITCYCLE,V_CUR_SERNUM,V_ZERO_FLAG,V_SEQUENCESTYLE FROM S_AUTOCODE T WHERE T.ATYPE=I_ATYPE AND T.OWNER=I_OWNER ; --¸ñʽ»¯µ±Ç°ÈÕÆÚ SELECT TO_CHAR(SYSDATE,'yyyy'), TO_CHAR(SYSDATE,'yyyyMM'), TO_CHAR(SYSDATE,'yyyyMMdd'), TO_CHAR(SYSDATE,'yyyyMMddHH24MISS') INTO V_DATE_YEAR,V_DATE_YEAR_MONTH,V_DATE_DATE,V_DATE_DATE_ALL FROM DUAL; -- ÈÕÆÚ´¦Àí O_AUTOCODE := REPLACE(V_SEQUENCESTYLE,'$YEAR$',V_DATE_YEAR); O_AUTOCODE := REPLACE(O_AUTOCODE,'$YEAR_MONTH$',V_DATE_YEAR_MONTH); O_AUTOCODE := REPLACE(O_AUTOCODE,'$DATE$',V_DATE_DATE); O_AUTOCODE := REPLACE(O_AUTOCODE,'$DATE_ALL$',V_DATE_DATE_ALL); --ËùÓÐÕß´¦Àí O_AUTOCODE := REPLACE(O_AUTOCODE,'$ORGAPP$',I_OWNER); --ÐòºÅ´¦Àí V_SEQ_NUM := TO_CHAR(TO_NUMBER(V_CUR_SERNUM)+TO_NUMBER(V_INITCYCLE)); --·´Ð´µ±Ç°ÐòÁкţ¬È·±£Ã¿´Î¶¼ÊǵÝÔö UPDATE S_AUTOCODE T SET T.CUR_SERNUM=V_SEQ_NUM WHERE T.ATYPE=I_ATYPE AND T.OWNER=I_OWNER ; --²»Âú×㳤¶ÈµÄÇ°Ãæ²¹0 IF LENGTH(V_SEQ_NUM) < TO_NUMBER(V_ZERO_FLAG) THEN ¡¡¡¡¡¡¡¡¡¡¡¡/* LOOP V_SEQ_NUM := '0'||V_SEQ_NUM; EXIT WHEN LENGTH(V_SEQ_NUM) = TO_NUMBER(V_ZERO_FLAG); END LOOP; ¡¡¡¡¡¡¡¡¡¡¡¡*/ ¡¡¡¡¡¡¡¡¡¡¡¡V_SEQ_NUM := LPAD(V_SEQ_NUM,TO_NUMBER(V_ZERO_FLAG),'0'); END IF; O_AUTOCODE := REPLACE(O_AUTOCODE,'$SER$',V_SEQ_NUM); COMMIT; RETURN O_AUTOCODE; EXCEPTION --Èç¹ûûÓжÔÓ¦µÄÅäÖÃÏÔò·µ»ØERRORÖµ WHEN NO_DATA_FOUND THEN ROLLBACK; DBMS_OUTPUT.put_line('there is no config as you need...'); RETURN 'ERROR'; END SF_SYS_GEN_AUTOCODE; |
»¶Ó¹âÁÙ ¶ÈÁ¿¿ìËÙ¿ª·¢Æ½Ì¨-רҵ¡¢¿ìËÙµÄÈí¼þ¶¨Öƿ쿪ƽ̨ (http://plat.delit.cn/) | Powered by Discuz! X3.2 |