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

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

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