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 PraDz <pr...@appliedevelopment.com> on 2007/04/13 09:12:56 UTC

Ibatis :: [usage of IN]

Dear all

i am using iBatis for the past 6 months and its really gud.

now i am using a query which will retrieve multiiple records.

i am using like this in the query xml
<statement id="getReportList" parameterClass="ReportVO"
resultMap="get_Report">

<![CDATA[

SELECT * FROM message where m_id IN(#m_id#) and m_type in (100,110) and
timestamp >=#startTime# and timestamp < #stopTime# order by m_id, timestamp;
]]>

</statement>

ex: m_id=1,2,3,4
but the resultset doesnt return records for different m_id. only it
retrieves data for the first m_id.

kindly let me know if i can use IN or is there any other way that i can use.

-- 
View this message in context: http://www.nabble.com/Ibatis-%3A%3A--usage-of-IN--tf3570116.html#a9974026
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Ibatis :: [usage of IN]

Posted by Koka Kiknadze <22...@gmail.com>.
Using #mi_id# tells iBatis to prepare statement
SELECT * FROM message where m_id IN( ? )  ...
and obviuosly it'll return records with m_id="1,2,3,4"  (i.e. not (1 or 2 or
3 or 4) but whole string "1,2,3,4").
Simplest way is to use $mi_id$. The $ signs tell iBatis to substitute
$mi_id$ with actual string (i.e. 1,2,3,4) and create statement after that
substitution.

I think usually you'll have values needed for IN clause stored in some kind
of list or array. For that case look for <iterate> tag in iBatis docs.