SELECT TO_CHAR(SYSDATE, 'YYYYMM') || 
       LPAD(NVL(MAX(SUBSTR(FAIL_HS_SEQ, -4)), '0000') + 1, 4, '0') AS NEWID
  FROM TB_FCLT_FAIL_HS
 WHERE SUBSTR(FAIL_HS_SEQ, 1, 6) = TO_CHAR(SYSDATE, 'YYYYMM')


SELECT * 
  FROM TB_FCLT_FAIL_HS 
 ORDER BY FAIL_HS_SEQ

SELECT * 
  FROM TB_FCLT_FAIL_RPAR_HS
 ORDER BY FAIL_HS_SEQ, CRTN_DT


SELECT TO_NUMBER(LPAD(NVL(MAX(SUBSTR(FAIL_HS_SEQ, -4)), '0000') + 1, 4, '0')) AS NEWID 
  FROM TB_FCLT_FAIL_HS                                                      
 WHERE SUBSTR(FAIL_HS_SEQ, 1, 6) = TO_CHAR(SYSDATE, 'YYYYMM')               
