mysql operations using variables as the table name

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed.

I want to use python mysql database operations to achieve the following results:
the sql statement table name is replaced with a variable operating table in batches

sql = "select * from sets where number = '%s' "

Sql statement sets the number and replaced with a variable, a plurality of tables for automatic operation:

1
2
3
4
table = "sets"
attr = "number"
sql = "select * from "+table+" where "+attr+" = '%s'"

Original link large column  https://www.dazhuanlan.com/2019/08/15/5d5514c4c63b6/

Guess you like

Origin www.cnblogs.com/chinatrump/p/11416268.html