比如,變量name = student pl = teacher #變量值是動態變化的。我想要的是如下的結果alter table student rename to teacher #修改表名,但是如果直接寫alter name name rename to pl則是修改名稱為name的表了
1 回答

紅糖糍粑
TA貢獻1815條經驗 獲得超6個贊
因為cursor.execute()函數的參數是一個字符串,所以可以用拼字符串的方式,把變量name和pl寫進數據庫命令中.
name = "student" pl = "teacher" cursor.execute( "alter table " + name + " rename to " + pl) |
添加回答
舉報
0/150
提交
取消