在Python中调用SQL存储过程的方法有以下几种:
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('mysql://user:password@localhost/dbname')
Session = sessionmaker(bind=engine)
session = Session()
result = session.execute("CALL stored_procedure_name()")
import pyodbc
conn = pyodbc.connect('DSN=DataSourceName;UID=user;PWD=password')
cursor = conn.cursor()
cursor.execute("{CALL stored_procedure_name()}")
conn.commit()
rows = cursor.fetchall()
import pymysql
conn = pymysql.connect(host='localhost', user='user', password='password', db='dbname')
cursor = conn.cursor()
cursor.callproc('stored_procedure_name', args=())
conn.commit()
result = cursor.fetchall()