你好我目前正在測驗 1 個資料庫中的 2 個表,我目前遇到了這個問題:
pC.execute("""CREATE TABLE IF NOT EXISTS LoanDB (
GPL REAL,
SLMV REAL,
MPLGSIS REAL,
CALAMITY REAL,
OPTLINST REAL,
SLCONSOLOAN REAL,
UOLILOAN REAL,
PLREG REAL,
EDUCASST REAL,
MPLPAGIBIG REAL,
CPL REAL,
GSISEMERG REAL)
""")
loantest = [(0.00,0.00,0.00,0.00,0.00,3613.68,0.00,0.00,0.00,0.00,0.00,0.00),(0.00,3000,0.00,5000.00,0.00,3613.68,0.00,0.00,0.00,0.00,0.00,0.00)]
pC.execute("""INSERT INTO LoanDB VALUES (?,?,?,?,?,?,?,?,?,?,?,?)""",loantest)
當我運行此代碼時,它開始出現如下錯誤:
pC.execute("""INSERT INTO LoanDB VALUES (?,?,?,?,?,?,?,?,?,?,?,?)""",loantest)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 12, and there are 2 supplied.
我確定我將變數 loantest 初始化為 list 但執行函式沒有通過
uj5u.com熱心網友回復:
這實際上是我的錯,我沒有看到它必須.executemany("""INSERT INTO LoanDB VALUES (?,?,?,?,?,?,?,?,?,?,?,?)""",loantest)代替的功能.execute("""INSERT INTO LoanDB VALUES (?,?,?,?,?,?,?,?,?,?,?,?)""",loantest)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/498263.html
