ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: dynamic query to pick up a sequence
Date Tue, 08 Nov 2005 22:52:31 GMT
If sequenceName is a property available to iBATIS at runtime, you can
use:

SELECT $sequenceName$.nextval FROM dual

iBATIS replaces the $'s with the value of the property, the #'s are for
setting parameters in a prepared statement.

Hope this helps,

Niels

-----Original Message-----
From: Tom Stockton [mailto:TStockton@Policy-Studies.com] 
Sent: dinsdag 8 november 2005 23:42
To: user-java@ibatis.apache.org
Subject: dynamic query to pick up a sequence

I've searched the archives, it doesn't look like this has come up
before.  This is an oracle example:

    <select id="fetchNextInSequence" resultClass="java.util.HashMap">
        Select #sequenceName#.nextval from dual
    </select>

in a nutshell, we want to pass the name of the sequence into the query
and get the result back.
For instance, if I execute the query with an sequenceName =
"APPLICATION_SEQ", we would want the following SQL to be executed:

Select APPLICATION_SEQ.nextval from dual

It looks like the sql being executed is something along the lines of

       select '#sequenceName#' nextval from dual

what comes back in the map is a key-value pair of
nextVal->APPLICATION_SEQ

Can I use this approach?  If not, is there another approach to give me
the same result (not having to code an individual query for each
sequence)?

thanks,

t





Mime
View raw message