cx_Oracle clause IN using a variable

Beppe giuseppecostanzi at gmail.com
Tue Oct 16 09:41:58 EDT 2012


Hi all,
I don't know if it is the correct place to set this question, however,
I'm using cx_Oracle to query an Oracle database.
I've a problem to use the IN clause with a variable.
My statement is 

sql = "SELECT field1,field2,field3
        FROM my_table
        WHERE field_3 IN (:arg_1)"

where arg_1 is retrive by a dictionary
that is build so

 my_dict = {'location':"X",
            'oracle_user':'user',
            'oracle_password':'pass',
            'dsn':'dsn',
            'mailto':'someone at somewhere.org',
            'codes':"CNI,CNP"}

args = (dict['codes'],)
           
 
con = cx_Oracle.connect(my_dict["oracle_user"],
                         my_dict["oracle_password"],
                         my_dict["dsn"])
                         
cur = con.cursor()
cur.execute(sql,args)
rs =  cur.fetchall()           

but it doesn't work in the sense that doesn't return anything

If i use the statment without variable 

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

the query works

what is wrong?
suggestions?

regards
beppe



More information about the Python-list mailing list