使用Python执行存储过程
使用Python执行存储过程[2部分]:
1.执行存储过程,获取存储过程的结果集
2.将返回值设置给了 @_存储过程名_序号 =
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='test_python', charset='utf8')
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
# 执行存储过程
# @_p3_0 = 1, 相当于Python帮我们创建了变量,所以返回值也是放在了这个变量里面,需要我们手动获取
# @_p3_1 = 2
# @_p3_2 = 3
# @_p3_3 = 0
ret1 = cursor.callproc('p3', args=(1, 2, 3, 0))
# print('ret1:', ret1) # 传递参数过去 ret1: (1, 2, 3, 0),同时执行了存储过程将结果放在内存
result = cursor.fetchall() # 从内存获取返回值,[{'@_p3_0': 1, '@_p3_3': 7, '@_p3_1': 2