Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31420

Re: cx_Oracle clause IN using a variable

References <013921b2-122e-4169-bb09-8973e0f07ec1@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-16 11:04 -0600
Subject Re: cx_Oracle clause IN using a variable
Newsgroups comp.lang.python
Message-ID <mailman.2292.1350407093.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Oct 16, 2012 at 7:41 AM, Beppe <giuseppecostanzi@gmail.com> wrote:
> Hi all,
> I don't know if it is the correct place to set this question, however,

The best place to ask questions about cx_Oracle would be the
cx-oracle-users mailing list.

> what is wrong?
> suggestions?

With the bind parameter you're only passing in a single string, so
your query is effectively equivalent to:

SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN ('CNI,CNP')

You can't pass an actual list into a bind parameter the way that you
would like.  You need to use a separate parameter for each item in the
list.  This may mean constructing the query dynamically:

in_vars = ','.join(':%d' % i for i in xrange(len(sequence_of_args)))

sql = """
SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN (%s)
""" % in_vars

cursor.execute(sql, sequence_of_args)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

cx_Oracle clause IN using a variable Beppe <giuseppecostanzi@gmail.com> - 2012-10-16 06:41 -0700
  Re: cx_Oracle clause IN using a variable Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-16 11:04 -0600
  Re: cx_Oracle clause IN using a variable Hans Mulder <hansmu@xs4all.nl> - 2012-10-16 19:22 +0200
    Re: cx_Oracle clause IN using a variable Beppe <giuseppecostanzi@gmail.com> - 2012-10-17 06:49 -0700

csiph-web