Varibles in SQL statements

Lee, Jaeho Jhlee at
Fri May 19 19:56:45 CEST 2000

Do you want to use Oracle bind variable? 
If not you can do this.

var = "'1'"
mycursor.execute("SELECT userID FROM userTable WHERE userID=%s" % var)

In sql, string should be quoted (not double quoted). And excute() method
receives just string in this case. var in your sql is just var and the
database try to find a database field named 'var'. That's why.

I don't know how to use bind variable. So I can not help for that.

-----Original Message-----
From: relder at [mailto:relder at]
Sent: Friday, May 19, 2000 1:38 PM
To: python-list at
Subject: Varibles in SQL statements


   I don't understand how to use (or format really) varibles in SQL.With
the sequence

var = '1'
mycursor.execute('SELECT userID FROM userTable WHERE userID=var')

I get a too few paramerters error 

This does work:

mycursor.execute("SELECT userID FROM userTable WHERE userID='1'") 




More information about the Python-list mailing list