每当我尝试运行此代码时,它都会收到TypeError:'int'和'tuple'错误实例之间不支持'<',因为它返回int并另存为元组,并且当我尝试分配返回值时 就像它不是一个不能使用“ <> + =-”的整数
import cx_Oracle
conn = cx_Oracle.connect('emu/emu@127.0.0.1')
cur = conn.cursor()
cur.execute("select max(locationid) from location")
for line in cur:
maxID = line
IDofcity = 1
while IDofcity < maxID:
cur.execute(f"select city from location where locationid='{IDofcity}'")
for row in cur:
Nameofcities = ['']
Nameofcities.append(row)
IDofcity += 1
print(Nameofcities)
cur.close()
conn.close()
代码与错误
答案 0 :(得分:1)
您尝试过吗:
for line in cur:
(maxID,) = line
这使maxID引用元组中的值,而不是元组本身。
如果元组中有1个以上的项目,您将得到:
ValueError: too many values to unpack (expected 1)