日期:2014-05-16 浏览次数:20472 次
CREATE SEQUENCE SEQ_HEX MINVALUE 0 MAXVALUE 10000000 START WITH 0 INCREMENT BY 1 CACHE 20 CYCLE ORDER;
CREATE OR REPLACE FUNCTION getHexSequence RETURN VARCHAR2 AS N_SHANG NUMBER(10); N_YUSHU NUMBER(10); HEXRES VARCHAR2(10); BEGIN N_SHANG :=seq_hex.NEXTVAL; IF N_SHANG = 0 THEN RETURN '00000'; END IF; WHILE N_SHANG>0 LOOP N_YUSHU:=N_SHANG MOD 16; SELECT CONCAT(DECODE(N_YUSHU,'10','A','11','B','12','C','13','D','14','E','15','F',N_YUSHU),HEXRES) INTO HEXRES FROM DUAL; N_SHANG := TRUNC(N_SHANG/16); END LOOP; RETURN LPAD(HEXRES,5,0); END;
SQL> SELECT getHexSequence FROM dual; GETHEXSEQUENCE ---------------------------------------- 000AD