【发布时间】:2018-04-17 02:41:12
【问题描述】:
我正在编写一个程序,可以将面包添加到 Oracle 11g 数据库中。到目前为止,我的代码允许我手动添加 ID,但添加时应该自动递增,因此不需要 ID。
BreadID = int(input("Enter the bread ID: "))
Name = input("Please enter the name for the new bread: ")
LoafPrice = int(input("Enter the price in pence: "))
Calories = int(input("Enter the calories: "))
cur.execute("INSERT INTO BREAD VALUES (:BID,:BName,:BCal,:BPrice)",{'BID':BreadID, 'BName':Name, 'BPrice':LoafPrice, 'BCal':Calories,})
con.commit()
这是我手动添加的代码。我在网上搜索了如何添加自动增量的答案,但都未能为我提供错误和更多问题。
我在网上看到,只留下 ID 列将允许自动递增,但我得到这个“ORA-00947:没有足够的值”,即使我已经指定了列名。
感谢任何帮助,因为我已经坚持了一段时间了。:)
【问题讨论】:
-
如您所说,它应该与离开 ID 列一起使用。你确定你在两个地方都留空了吗,我的意思是 VALUES() 和 {}?
-
是肯定的。这就是我所拥有的 'cur.execute("INSERT INTO BREAD VALUES (:BName,:BCal,:BPrice)",{'BName':Name, 'BPrice':LoafPrice, 'BCal':Calories,})' 和我收到错误“ORA-00947:没有足够的值”。
标签: python sql python-3.x oracle oracle11g