使用MySQLdb调用python中的存储过程时出错

2024-09-27 04:28:40 发布

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

我有一个名为test的MySQL存储过程,它接受一个参数。 我可以使用下面的代码执行python2.7x中的存储过程

data='Teststr'
cur = db.cursor()
cur.execute("CALL test('{0}')".format(data))

但当我使用

^{pr2}$

我遇到了

OperationalError: (1318, 'Incorrect number of arguments for PROCEDURE MyDb.test; expected 1, got 7')

看起来python将每个字符视为一个参数。我错过了什么?在


Tags: testformatexecutedbdata参数过程mysql
1条回答
网友
1楼 · 发布于 2024-09-27 04:28:40

您希望cur.callproc('test', (data,))传递1个元素的元组

例如:

>>> a = 'hello'
>>> len(a) # just a
5
>>> len( (a) ) # still just a
5
>>> len( (a,) ) # single element tuple containing a
1

相关问题 更多 >

    热门问题