如何解决如何在Python中将参数传递给SQL语句
我有一个Python脚本,该脚本正在调用执行SQL select语句的函数,但我不断收到令牌?无效。如何传递变量以便它们与SQL语句一起使用?这是我的代码:
def get_jde_udc_info(connection,product_code,userCode,librTable):
c1=connection.cursor()
length=c1.execute("select dtcdl,dtcnum from ?",(librTable) + " where dtsy=?",(product_code) + " and dtrt=?",(userCode))
length=c1.fetchall() # <-- Using the .fetchone method from the Python cursor class that will return a single record or None if no more rows are available
print(length)
这是我脚本中的函数调用:
get_jde_udc_info(connection,"41","s1","testctl.f0004")
解决方法
我喜欢使用%
赞:
"SELECT field1,field2 FROM %s WHERE email = '%s'" % ('table','johndoe@gmail.com')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。