lists in cx_Oracle

Andrew Dalke dalke at dalkescientific.com
Sat Apr 30 13:02:16 EDT 2005


A while back I asked about which Oracle client to use for
MS Windows.  Turns out I also needed one for unix so I followed
people's advice and installed cx_Oracle.

I want to execute a query with an "IN" in the WHERE clause
and with the parameter taken from a Python variable.  That
is, I wanted something like this to work

id_list = ["AB001", "AB002", "AB003"]

c.execute("""SELECT s.smiles FROM smiles_database s WHERE """
         """  s.id IN :id_list""", id_list = id_list)

I couldn't get it to work.  It complained

    arrays can only be bound to PL/SQL statements

I tried looking at the source code but couldn't figure out
how to do this.  In no small part due to my nearly complete
lack of experience with Oracle or for that matter SQL databases.

My solution was to build a new string to executed but it
wasn't pretty and I needed to explain to my client about
SQL injection; wanted to use repr(a_tuple) which was *almost*
correct.

How do I do what I want to do?

				Andrew
				dalke at dalkescientific.com




More information about the Python-list mailing list