diff --git a/src/main/resources/sql/mapper/fims/numbering.xml b/src/main/resources/sql/mapper/fims/numbering.xml index 174d4c3a..eced5a79 100644 --- a/src/main/resources/sql/mapper/fims/numbering.xml +++ b/src/main/resources/sql/mapper/fims/numbering.xml @@ -3,31 +3,48 @@ -SELECT - LPAD(CAST(IFNULL(MAX(${TABLE_KEY}) + 1, 1) AS INT), ${pad}, '0') - AS NEW_ID - FROM ${TABLE_NAME} +SELECT LPAD(CAST( + CASE + WHEN (SELECT MAX(${TABLE_KEY}) + 1 FROM ${TABLE_NAME}) IS NULL OR + (SELECT MAX(${TABLE_KEY}) + 1 FROM ${TABLE_NAME}) = '' + THEN 1 + ELSE (SELECT MAX(${TABLE_KEY}) + 1 FROM ${TABLE_NAME}) + END + AS INT), ${pad}, '0') +AS NEW_ID +FROM DUAL -SELECT - CONCAT( - - , LPAD(CAST(IFNULL(MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1, 1) AS INT), ${pad}-4, '0') - ) AS NEW_ID - FROM ${TABLE_NAME} - WHERE ${TABLE_KEY} LIKE CONCAT(, '%') +SELECT CONCAT(, LPAD(CAST( + CASE + WHEN (SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(, '%')) IS NULL OR + (SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(, '%')) = '' + THEN 1 + ELSE (SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(, '%')) + END + AS INT), ${pad}-4, '0')) +AS NEW_ID +FROM DUAL -SELECT - CONCAT( - ${sggCd} - , - , LPAD(CAST(IFNULL(MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1, 1) AS INT), ${pad}-9, '0') - ) AS NEW_ID - FROM ${TABLE_NAME} - WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, , '%') +SELECT CONCAT(, LPAD(CAST( + CASE + WHEN (SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, , '%')) IS NULL OR + (SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, , '%')) = '' + THEN 1 + ELSE (SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME} + WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, , '%')) + END + AS INT), ${pad}-9, '0')) +AS NEW_ID +FROM DUAL \ No newline at end of file