Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Parameterizing queries with SQL "IN" clauses
Eric Bell wrote:
>
> I have query that I am calling using JDBC. The query has an "IN" clause in
> it:
>
> select *
> from table1
> where id in (123,234,234,234);
>
> I would like to be able to pass the values in the "IN" clause via a
> parameter, such as:
>
> select *
> from table1
> where id in (?);
>
> Then in my JDBC code I would have:
>
> preparedStatement.setString(1, "123,234,234,234" );
>
> This doesn't work, which doesn't surprise me. But does anybody know a way to
> do this, or do I have to build my IN clause in code?
>
> Thanks
You'd be much better off using bind variables, and have a distinct number of permutations, maybe
x in (:b1, :b2, :b3, :b4, :b5) for up to 5 possible values x in (:b1, :b2, :b3, ... :b10) for up to 10 possible values
I can't stress to you enough - don't use static values in your SQL's - its asking for grief...
HTH
-- =========================================== Connor McDonald http://www.oracledba.co.uk (mirrored at http://www.oradba.freeserve.co.uk) "Early to bed and early to rise, makes a man healthy, wealthy and wise." - some dead guyReceived on Fri Oct 20 2000 - 05:17:54 CDT