存储过程:
CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
BEGIN
SET pProd := pFac1 * pFac2;
END;
调用
>>> args = (5, 6, 0) # 0 is to hold value of the OUT parameter pProd
>>> cursor.callproc('multiply', args)
('5', '6', 30L)
存储过程:
CREATE PROCEDURE sp1(IN pStr1 VARCHAR(20), IN pStr2 VARCHAR(20),
OUT pConCat VARCHAR(100))
BEGIN
SET pConCat := CONCAT(pStr1, pStr2);
END;
调用:
args = ('ham', 'eggs', (0, 'CHAR'))
result_args = cursor.callproc('sp1', args)
print(result_args[2])
callproc第二个参数是序列容器,一般是元组
Method MySQLCursor.stored_results()
调用 callproc()后,产生的结果集合可以用该函数获取。
>>> cursor.callproc('sp1')
()
>>> for result in cursor.stored_results():
... print result.fetchall()