[每当我尝试运行此代码时,它都会得到TypeError:' + =-”的整数
import cx_Oracle
conn = cx_Oracle.connect('emu/[email protected]')
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()
代码和错误
您是否尝试过:
for line in cur:
(maxID,) = line
这使maxID引用元组中的值,而不是元组本身。
如果元组中有1个以上的项目,您将得到:
ValueError: too many values to unpack (expected 1)