0
我在使用Python爲Oracle數據庫創建SQL查詢時遇到了問題。 我想綁定字符串變量,它不起作用,你能告訴我我做錯了什麼? 這是我的代碼:Python cx_Oracle SQL綁定字符串變量
import cx_Oracle
dokList = []
def LoadDatabase():
conn = None
cursor = None
try:
conn = cx_Oracle.connect("login", "password", "localhost")
cursor = conn.cursor()
query = "SELECT * FROM DOCUMENT WHERE DOC = :param"
for doknumber in dokList:
cursor.execute(query, {'doknr':doknumber})
print(cursor.rowcount)
except cx_Oracle.DatabaseError as err:
print(err)
finally:
if cursor:
cursor.close()
if conn:
conn.close()
def CheckData():
with open('changedNamed.txt') as f:
lines = f.readlines()
for line in lines:
dokList.append(line)
CheckData()
LoadDatabase()
的cursor.rowcount
輸出爲0,但它應該是數量大於0
好吧,我改變了它,但'cursor.rowcount'的值仍然是0,'select:from dual'的doknr也不起作用... – fafal
rowcount將用於DML。對於查詢,使用SELECT COUNT來獲取行數。 –