getting results from IBM DB2 stored procedure #1384
Unanswered
DeltaFox0018
asked this question in
Q&A
Replies: 4 comments 8 replies
-
You might try this: cursor.execute(sql)
try:
rows = cursor.fetchall()
except pyodbc.ProgrammingError:
cursor.nextset()
rows = cursor.fetchall()
print(rows) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have tried but the error is the same |
Beta Was this translation helpful? Give feedback.
0 replies
-
A more robust approach would be cursor.execute(sql)
rows = []
fetching = True
while fetching:
try:
rows = cursor.fetchall()
fetching = False
except pyodbc.ProgrammingError:
fetching = cursor.nextset()
print(rows) |
Beta Was this translation helpful? Give feedback.
0 replies
-
pyodbc doesn't support output parameters. There's a workaround documented here |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please first make sure you have looked at:
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be
sure to specify 32-bit Python or 64-bit:
Issue
I have a procedure with 3 parameters, 2 input and 1 output.
From DBeaver if I call the procedure as follows
CALL my_procedure('user','psw', ?)
I have an output of the following type

Through pyodbc I configured the connection to the DB and ran the same call
`
cnxn = pyodbc.connect("DRIVER=IBM i Access ODBC Driver;SYSTEM=MYIP;UID=USER;PWD=PSW;")
`
Running the print either you fetchall, fetchone or fetchval or the following error
Traceback (most recent call last): File "/Users/alessandrovolpato/Desktop/rapportini-backend/main.py", line 43, in <module> print(cursor.fetchone()) ^^^^^^^^^^^^^^^^^ pyodbc.ProgrammingError: No results. Previous SQL was not a query.
Do you know how I can retrieve the output of the procedure?
Beta Was this translation helpful? Give feedback.
All reactions