<choose>
1. 조건과 조건에 맞지 않을 경우 동적 제어
<choose>
<when test="type != '' and type != NULL">
-- 조건에 해당하면
</when>
<otherwise>
-- 그렇지 않으면
</otherwise>
</choose>
2. 조건이 무엇인지에 따라 동적 제어
<choose>
<when test="type.equals('day') ">
-- type이 day일 경우
</when>
<when test="type.equals('month') ">
-- type이 month일 경우
</when>
</choose>
3. AND(A OR B)
<choose>
<when test='type1 == "N"'>
AND (TYPE_A IS NULL
</when>
<when test='type1 != null and type1 != "" and type1 !="N"'>
AND (TYPE_A = #{type1}
</when>
<otherwise>
-- 항상 참 (열기 위해 사용)
AND ( 1=1
</otherwise>
</choose>
<choose>
<when test='type2 == "N"'>
AND (TYPE_B IS NULL
</when>
<when test='type2 != null and type2 != "" and type2 !="N"'>
AND (TYPE_B = #{type2}
</when>
<otherwise>
-- 항상 참 (닫기 위해 사용)
OR 1=1 )
</otherwise>
</choose>
'개발 > DATABASE' 카테고리의 다른 글
[SQL] 특정일 기준 일주일 구하기 (월-일, 일-토) (0) | 2023.08.16 |
---|---|
[SQL] 조건절에서 기간, 시간 중복 체크 (0) | 2023.08.14 |
[SQL] function에 임시테이블 생성하기 (0) | 2023.08.02 |
Lock wait timeout exceeded; try restarting transaction (0) | 2019.03.29 |