python执行sql

2022-05-20  本文已影响0人  Quick_5413

执行单条:
P_list=[2,'name']
MySQL:cursor.execute('select * from user where id = ? and name = ? ', (P_list))
Oracle:cursor.execute('select * from user where id = :id and name = :name ', (P_list))

执行多条:
sql= 'insert into user (id,name) values(?,?)'
content_list=[(1,'a'),(2,'b'),(3,'c')]
MySQL:cursor.executemany(sql,content_list)#执行多条SQL

上一篇 下一篇

猜你喜欢

热点阅读