You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by anson <an...@linkclub-staff.com> on 2006/01/26 09:36:59 UTC
How to use SQL's "IN" with iBatis
Dears,
Could any one tell me how to use "IN" with iBatis?
For example:
case 1:
String key = "01,02,03";
select table.colum1 from table where table.colum2 IN (#key#)
I can not get anything.
case 2:
String key = "01";
select table.colum1 from table where table.colum2 IN (#key#)
I can get the right result.
case 3:
String key = "'01'"
select table.colum1 from table where table.colum2 IN (#key#)
I can not get anything.
How can I get right result with iBatis like this SQL:
select table.colum1 from table where table.colum2 IN ('01', '02', '03');
Best Regards!!
Re: How to use SQL's "IN" with iBatis
Posted by Guido García Bernardo <gg...@tid.es>.
Hi,
You can use the <iterate> tag:
String[] key = { "01" , "02", "03" };
case 1: using IN as you want
select table.column1 from table where table.column2 IN
<iterate property="key" open="(" close=")" conjunction=",">
#key[]#
</iterate>
case 2: using OR as an alternative
select table.column1 from table where
<iterate property="key" conjunction="OR">
table.column2 = #key[]#
</iterate>
Maybe there is some typo, but you get the idea.
Best regards,
anson escribió:
> Dears,
>
> Could any one tell me how to use "IN" with iBatis?
>
> For example:
>
> case 1:
>
> String key = "01,02,03";
>
> select table.colum1 from table where table.colum2 IN (#key#)
>
> I can not get anything.
>
>
>
>
>
> case 2:
>
> String key = "01";
>
> select table.colum1 from table where table.colum2 IN (#key#)
>
> I can get the right result.
>
>
>
>
>
> case 3:
> String key = "'01'"
>
> select table.colum1 from table where table.colum2 IN (#key#)
>
> I can not get anything.
>
>
>
>
>
> How can I get right result with iBatis like this SQL:
>
> select table.colum1 from table where table.colum2 IN ('01', '02', '03');
>
> Best Regards!!
>
>
>
>
>
>
--
Guido García Bernardo
have a nice wifree !
Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid
Re: How to use SQL's "IN" with iBatis
Posted by Jozef Hribik <jo...@apsoft.sk>.
String[] key;
select table.colum1 from table
<dynamic>
<isNotEmpty prepend="WHERE" property="key">
table.colum2
<iterate property="var1" open=" IN (" close=")" conjunction=",">
#key[]#
</iterate>
</isNotEmpty>
</dynamic>
anson wrote:
>Dears,
>
>Could any one tell me how to use "IN" with iBatis?
>
>For example:
>
>case 1:
>
>String key = "01,02,03";
>
>select table.colum1 from table where table.colum2 IN (#key#)
>
>I can not get anything.
>
>
>
>
>
>case 2:
>
>String key = "01";
>
>select table.colum1 from table where table.colum2 IN (#key#)
>
>I can get the right result.
>
>
>
>
>
>case 3:
>String key = "'01'"
>
>select table.colum1 from table where table.colum2 IN (#key#)
>
>I can not get anything.
>
>
>
>
>
>How can I get right result with iBatis like this SQL:
>
>select table.colum1 from table where table.colum2 IN ('01', '02', '03');
>
>Best Regards!!
>
>
>
>
>
>__________ Informacia od NOD32 1.1380 (20060125) __________
>
>Tato sprava bola preverena antivirusovym systemom NOD32.
>http://www.eset.sk
>
>
>
>__________ Informacia od NOD32 1.1380 (20060125) __________
>
>Tato sprava bola preverena antivirusovym systemom NOD32.
>http://www.eset.sk
>
>
>
>
>