存儲過程:
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()