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:[EMAIL PROTECTED] 
Sent: dinsdag 8 november 2005 23:42
To: [email protected]
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




Reply via email to