CREATE OR REPLACE FUNCTION TS.F_Seq RETURN VARCHAR2 IS
tmpSEQ NUMBER;
rtnSEQ VARCHAR2(12);
BEGIN
tmpSEQ := 0;
rtnSEQ := '';
SELECT NVL(TO_NUMBER(SUBSTR(MAX(SEQNO),12)),0) INTO tmpSEQ FROM TB__MASTER
WHERE SEQNO LIKE TO_CHAR(SYSDATE,'YYYYMMDD') || '%';
SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') || '-' || LPAD(TO_CHAR(tmpSEQ+1),3,'0') INTO rtnSEQ FROM DUAL;
RETURN rtnSEQ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN TO_CHAR(SYSDATE, 'YYYYMMDD') || '-001';
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END F_Seq;
/
댓글 없음:
댓글 쓰기