当我尝试在 python 中执行存储过程时出现错误。我正在使用 python 2.7 和 mysql。
当我从 mysql workbench 调用它或从命令行调用时,存储过程工作。
这是代码。
class db_conn:
def __init__(self,db_name):
self.conn = mysql.connector.connect(user = 'test', password = 'test', host = 'localhost', database = 'test')
self.cursor = self.conn.cursor()
self.return_data = []
def select_procedure(self, proc):
print(proc)
self.cursor.callproc(proc,'')
self.conn.commit()
return cursor.stored_results()
我收到以下错误。
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
这是存储过程。没什么大不了的。
DELIMITER $$
CREATE DEFINER=`test`@`localhost` PROCEDURE `get_info`()
BEGIN
Select id, fname,lname
From name_table
where display = 0 limit 1;
END
最佳答案
您缺少 SP 的关闭信息:
DELIMITER $$
CREATE DEFINER=`test`@`localhost` PROCEDURE `get_info`()
BEGIN
Select id, fname,lname
From name_table
where display = 0 limit 1;
END$$
DELIMITER ;
关于Python 存储过程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46637237/