擅长:python、mysql、java
<p>SQLAlchemy没有这样的功能。这些“低级”命令如:insert、insertmany、callproc、execute、cursor等由<strong>DBAPI</strong>(<a href="https://www.python.org/dev/peps/pep-0249" rel="nofollow noreferrer">Python DB API Specification</a>)驱动程序提供,如cx-Oracle、psycopg2、MySQL-Python等。。。SQLAlchemy只是代理DBAPI驱动程序提供的这些函数。你知道吗</p>
<p>如果需要执行函数,应使用<a href="https://www.python.org/dev/peps/pep-0249/#cursor" rel="nofollow noreferrer">callproc</a>游标方法:</p>
<pre><code>args_for_multiple_calls = [
{"a1": 1, "a2": "dfg4"),
{"a1": 4, "a2": "ger"),
{"a1": 2, "a2": "sfg3"),
]
conn = engine.raw_connection()
try:
cursor = conn.cursor()
for x in args_for_multiple_calls:
cursor.callproc("my_stored_func", [x['a1'], x['a2']])
results = list(cursor.fetchall())
conn.commit()
cursor.close()
finally:
conn.close()
</code></pre>