001 002 .. 999 A00 A01 .. A10 .. A99 AA0 .. AZZ B00 ... ZZZ
요로 고럼 순번 채번을 하고 싶은데요 쉽지가 않네요 ...고수님들 도움부탁드립니다. ^^;;
--시퀀스생성 CREATE SEQUENCE SEQ_HAHA START WITH 1 MAXVALUE 33696 MINVALUE 1 CYCLE CACHE 10 ORDER; --펑션생성 CREATE OR REPLACE FUNCTION FUNC_HAHA RETURN VARCHAR2 IS SEQ_ID NUMBER; VAR_RTN VARCHAR2(3); BEGIN SELECT TO_CHAR(SEQ_HAHA.NEXTVAL) INTO SEQ_ID FROM DUAL; IF SEQ_ID < 1000 THEN SELECT LPAD(SEQ_ID, 3, '0') INTO VAR_RTN FROM DUAL; ELSE SELECT DECODE(MOD(CEIL((TO_NUMBER(SEQ_ID)-999) / 36 /36), 26),1,'A',2,'B',3,'C',4,'D',5,'E',6,'F',7,'G',8,'H',9,'I',10,'J',11,'K',12,'L',13,'M',14,'N',15,'O',16,'P',17,'Q',18,'R',19,'S',20,'T',21,'U',22,'V',23,'W',24,'X',25,'Y',0,'Z') ||DECODE(MOD(CEIL(((TO_NUMBER(SEQ_ID)-999) /36)),36),1,'0',2,'1',3,'2',4,'3',5,'4',6,'5',7,'6',8,'7',9,'8',10,'9',11,'A',12,'B',13,'C',14,'D',15,'E',16,'F',17,'G',18,'H',19,'I',20,'J',21,'K',22,'L',23,'M',24,'N',25,'O',26,'P',27,'Q',28,'R',29,'S',30,'T',31,'U',32,'V',33,'W',34,'X',35,'Y',0,'Z') ||DECODE(MOD((TO_NUMBER(SEQ_ID)-999), 36),1,'0',2,'1',3,'2',4,'3',5,'4',6,'5',7,'6',8,'7',9,'8',10,'9',11,'A',12,'B',13,'C',14,'D',15,'E',16,'F',17,'G',18,'H',19,'I',20,'J',21,'K',22,'L',23,'M',24,'N',25,'O',26,'P',27,'Q',28,'R',29,'S',30,'T',31,'U',32,'V',33,'W',34,'X',35,'Y',0,'Z') AS R_VAR INTO VAR_RTN FROM DUAL; END IF;
RETURN VAR_RTN; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN(''); WHEN OTHERS THEN RETURN(''); END FUNC_HAHA; /
--펑션 호출 SELECT FUNC_HAHA() FROM DUAL;
얼추 간단히 테스트는 해봤는데....
시퀀스랑 펑션 생성하셔서 이리저리 테스트 해보세요....
무한사랑 감사합니다 ^^