javasqloracle-databasegroovyvariable-binding

How can I use oracle variable binding within IN-keyword


I use variable binding in ORACLE with java/groovy like these:

String sql = "SELECT * FROM myTable WHERE id = :id"
sqlConnection.query(sql, [id: 111])

It works perfect. But when I try the same with an IN-keyword I got an error:

String sql = "SELECT * FROM myTable WHERE id IN(:ids)"
sqlConnection.query(sql, [ids: [111, 222, 333]])

When I execute it I got this error: java.sql.SQLException: Invalid column type

Has anybody an idea?


Solution

  • It won't work like that. It is possible only if you have a bind variable fore each of the members of the list. An alternative would be not to use a bind variable at all in case of the in list, but just pass the whole list as a string to Oracle.