채번 SQL 수정(null 관련 DB설정값, max 관련 DB설정값에 따른 영향 없도록 수정)

main
이범준 5 months ago
parent 3ee1947b77
commit 920d4b1d6d

@ -3,31 +3,48 @@
<mapper namespace="numbering">
<sql id="key">
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
</sql>
<sql id="keyByYear">
SELECT
CONCAT(
<include refid="utility.currentYear" />
, 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(<include refid="utility.currentYear" />, '%')
SELECT CONCAT(<include refid="utility.currentYear" />, LPAD(CAST(
CASE
WHEN (SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(<include refid="utility.currentYear" />, '%')) IS NULL OR
(SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(<include refid="utility.currentYear" />, '%')) = ''
THEN 1
ELSE (SELECT MAX(SUBSTRING(${TABLE_KEY}, 4+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(<include refid="utility.currentYear" />, '%'))
END
AS INT), ${pad}-4, '0'))
AS NEW_ID
FROM DUAL
</sql>
<sql id="keyBySggAndYear">
SELECT
CONCAT(
${sggCd}
, <include refid="utility.currentYear" />
, 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}, <include refid="utility.currentYear" />, '%')
SELECT CONCAT(<include refid="utility.currentYear" />, LPAD(CAST(
CASE
WHEN (SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, <include refid="utility.currentYear" />, '%')) IS NULL OR
(SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, <include refid="utility.currentYear" />, '%')) = ''
THEN 1
ELSE (SELECT MAX(SUBSTRING(${TABLE_KEY}, 9+1)) + 1 FROM ${TABLE_NAME}
WHERE ${TABLE_KEY} LIKE CONCAT(${sggCd}, <include refid="utility.currentYear" />, '%'))
END
AS INT), ${pad}-9, '0'))
AS NEW_ID
FROM DUAL
</sql>
</mapper>
Loading…
Cancel
Save