From 920d4b1d6de4eb22513dea26a8140ce6ad4bb351 Mon Sep 17 00:00:00 2001 From: leebj Date: Mon, 1 Jul 2024 12:53:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B1=84=EB=B2=88=20SQL=20=EC=88=98=EC=A0=95(n?= =?UTF-8?q?ull=20=EA=B4=80=EB=A0=A8=20DB=EC=84=A4=EC=A0=95=EA=B0=92,=20max?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20DB=EC=84=A4=EC=A0=95=EA=B0=92=EC=97=90?= =?UTF-8?q?=20=EB=94=B0=EB=A5=B8=20=EC=98=81=ED=96=A5=20=EC=97=86=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/sql/mapper/fims/numbering.xml | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) 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