SELECT TO_NUMBER(CASE WHEN EXISTS (SELECT 1 FROM TB_RSE_OFFR_SECT_MNGM)                
                             THEN (SELECT TRIM(MAX(TO_NUMBER(OFFR_SECT_ID)) + 1) 
                                     FROM TB_RSE_OFFR_SECT_MNGM) 
                             ELSE '1' END) AS NEWID                                                                
  FROM DUAL                                                                              

SELECT TO_NUMBER(CASE WHEN EXISTS (SELECT 1 FROM TB_RSE_OFFR_SECT_MNGM)
                             THEN (SELECT TRIM(MAX(TO_NUMBER(OBU_ENTR_DRCT_NMBR)) + 1) 
                                     FROM TB_RSE_OFFR_SECT_MNGM 
                                    WHERE ID = '')
                             ELSE '1' END) AS AUTONUM 
FROM DUAL 




SELECT A.OFFR_SECT_ID, A.OFFR_DRCT_NM, A.CNGS_BASI_SPED, A.DELY_BASI_SPED, 
       A.ID, A.OBU_ENTR_DRCT_NMBR, C.PRE_ID, C.IXR_DRCT_NUM,
       (SELECT ISTL_LCTN_NM FROM TB_RSE_MSTR WHERE ID = A.ID)     TARGETNM,                                
       (SELECT ISTL_LCTN_NM FROM TB_RSE_MSTR WHERE ID = C.PRE_ID) PRENM                                
  FROM TB_RSE_OFFR_SECT_MNGM A, 
       TB_RSE_OFFR_DRCT_INFR C 
WHERE A.ID = C.ID(+)                                                                                     
  AND A.OBU_ENTR_DRCT_NMBR = C.OBU_ENTR_DRCT_NMBR(+)                                                     
 ORDER BY TO_NUMBER(A.OFFR_SECT_ID)                                                              


--RSE 제공 구간 관리(정보제공구간정보)
SELECT OFFR_SECT_ID,
       OFFR_DRCT_NM,
       CNGS_BASI_SPED,
       DELY_BASI_SPED,
       ID,
       OBU_ENTR_DRCT_NMBR 
  FROM TB_RSE_OFFR_SECT_MNGM
 ORDER BY OFFR_SECT_ID

--RSE 제공 구간 정보(링크레벨2)
SELECT OFFR_SECT_ID,
       IFSC_ID,
       ORD
  FROM TB_RSE_OFFR_SECT_INFR

--RSE 제공 방향 정보
SELECT ID, 
       OBU_ENTR_DRCT_NMBR, 
       PRE_ID, 
       IXR_DRCT_NUM 
  FROM TB_RSE_OFFR_DRCT_INFR
  

SELECT A.OFFR_SECT_ID, A.OFFR_DRCT_NM, A.CNGS_BASI_SPED, A.DELY_BASI_SPED, A.ID, A.OBU_ENTR_DRCT_NMBR, 
       B.IFSC_ID, B.ORD, C.PRE_ID, C.IXR_DRCT_NUM,                                                                       
       D.F_NODE_ID, (SELECT NODE_NAME FROM TB_NODE WHERE NODE_ID = D.F_NODE_ID) F_NODENAME,            
       D.T_NODE_ID, (SELECT NODE_NAME FROM TB_NODE WHERE NODE_ID = D.T_NODE_ID) T_NODENAME,            
       (SELECT ISTL_LCTN_NM FROM TB_RSE_MSTR WHERE ID = A.ID) TARGETNM,                                
       (SELECT ISTL_LCTN_NM FROM TB_RSE_MSTR WHERE ID = C.PRE_ID) PRENM                                
  FROM TB_RSE_OFFR_SECT_MNGM A, 
       TB_RSE_OFFR_SECT_INFR B, 
       TB_RSE_OFFR_DRCT_INFR C, 
       TB_IFSC D              
WHERE A.OFFR_SECT_ID = B.OFFR_SECT_ID(+)                                                               
  AND A.ID = C.ID(+)                                                                                     
  AND A.OBU_ENTR_DRCT_NMBR = C.OBU_ENTR_DRCT_NMBR(+)                                                     
  AND B.IFSC_ID = D.IFSC_ID(+)                                                                           
 ORDER BY TO_NUMBER(A.OFFR_SECT_ID), B.ORD                                                              




DELETE TB_RSE_OFFR_SECT_INFR WHERE OFFR_SECT_ID = :p01

DELETE TB_RSE_OFFR_INFR_HS	 WHERE OFFR_SECT_ID = :p01

DELETE TB_RSE_OFFR_SECT_MNGM WHERE OFFR_SECT_ID = :p01





SELECT * FROM TB_RSE_OFFR_DRCT_INFR
