SQL/IBATIS
ibatis에서 or절 사용하기
nineDeveloper
2014. 4. 12. 22:22
728x90
반응형
if(name.equals("A") || name.equals("B")) 를 ibatis로 사용하고 싶은데요..
이 경우는 어쩔 수 없이,
< isEqual property="name" compareValue="A">
<isEqual property="name" compareValue="B">
...
</isEqual>
< /isEqual>
< isNotEqual property="name" compareValue="A">
<isEqual property="name" compareValue="B">
...
</isEqual>
</isNotEqual>
< isEqual property="name" compareValue="A">
<isNotEqual property="name" compareValue="B">
...
</isNotEqual>
</isEqual>
이런 식으로 세 가지 조건을 다 해줘야 할 것 같네요. 아니면 두 개가 중복되어도 상관없다면 그냥
<isEqual property="name" compareValue="A">
...
</isEqual>
< isEqual property="name" compareValue="B">
...
</isEqual>
와 같이 똑같은 조건으로 해도 되겠죠.
select *
from test
where 1 = 1
and 1 = 1
and 1 = 1
위와 같이 중복된다고 에러가 발생하지는 않으니까요.
도저히 감이 안잡히네요..
도움 좀 주세요..ㅜㅜ
아직까지 한 번도 or 조건으로 다이나믹쿼리를 만들 일이 없어서 생각도 못해봤는데...
이 경우는 어쩔 수 없이,
< isEqual property="name" compareValue="A">
<isEqual property="name" compareValue="B">
...
</isEqual>
< /isEqual>
< isNotEqual property="name" compareValue="A">
<isEqual property="name" compareValue="B">
...
</isEqual>
</isNotEqual>
< isEqual property="name" compareValue="A">
<isNotEqual property="name" compareValue="B">
...
</isNotEqual>
</isEqual>
이런 식으로 세 가지 조건을 다 해줘야 할 것 같네요. 아니면 두 개가 중복되어도 상관없다면 그냥
<isEqual property="name" compareValue="A">
...
</isEqual>
< isEqual property="name" compareValue="B">
...
</isEqual>
와 같이 똑같은 조건으로 해도 되겠죠.
select *
from test
where 1 = 1
and 1 = 1
and 1 = 1
위와 같이 중복된다고 에러가 발생하지는 않으니까요.
728x90
반응형