問題我有一個簡單的應用程序來查詢我的一些oracle表我希望能夠抓住我的文本框的工作價值,但是,我不斷得到這個錯誤任何幫助將不勝感激!如何在python中的sql select語句中使用多個變量?
test.py
def grabEnts():
global date
connection = cx_Oracle.connect('xxxxxxxx/[email protected]:xxxx/xxx')
cursor = connection.cursor()
startdate = e1.get()
enddate = e2.get()
#fs = datetime.date(startdate)
#fe = datetime.date(endate)
//this works but, I would like to use both startdate and endate
#cursor.execute("SELECT EMP_ID FROM TO_ENTRIES WHERE LEAVE_START >= '%s'" % startdate)
//Like this but I can't get it to work I keep getting this error
File "test.py", line 62, in grabEnts
cursor.execute('SELECT EMP_FIRST_NAME FROM TO_ENTRIES WHERE LEAVE_START >=%s AND LEAVE_END <=%s', startdate, enddate)
TypeError: function takes at most 2 arguments (3 given)
cursor.execute('SELECT EMP_FIRST_NAME FROM TO_ENTRIES WHERE LEAVE_START >=%s AND LEAVE_END <=%s', startdate, enddate)
for row in cursor:
outputent.writerow(row)
cursor.close()
connection.close()
多少參數,你傳遞給cursor.execute()?它有多少預期?什麼是錯誤的? ;-)順便說一下,我不能強調這一點,通常將用戶輸入直接插入到SQL中會打開一個所謂的SQL注入攻擊,因此應該像鼠疫一樣避免。你應該改用參數化查詢。看看這裏:http://bobby-tables.com/ –