使用python插入到

2024-09-26 17:57:01 发布

您现在位置:Python中文网/ 问答频道 /正文

使用参数表名插入。 什么是最理想和最好的方式

我有这个代码,它是有效的,但我在想是否有可能在一行上使用赋值。 这是我的密码

sql = """INSERT INTO {} (exchange, buy, sell) VALUES (% s,% s,% s)""". format (table)
         self.cursor.execute (sql, (exchange, buy, sell))
         self.connection.commit ()

试着这样做,但不起作用

         sql = """INSERT INTO {} (exchange, buy, sell) VALUES ({}, {}, {})""". format (table, exchange, buy, sell)

在最后一句中,返回未找到的错误。“mytable”

sql = """INSERT INTO %s (exchange, buy, sell) VALUES (% s,% s,% s)""% (table, exchange, buy, sell)

Tags: 代码selfformatsqlexchange方式tablebuy

热门问题