Varibles in SQL statements
Jhlee at Brooks.com
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.
From: relder at omegabit.com [mailto:relder at omegabit.com]
Sent: Friday, May 19, 2000 1:38 PM
To: python-list at python.org
Subject: Varibles in SQL statements
I don't understand how to use (or format really) varibles in SQL.With
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