pyodbc return multiple cursors from stored procedure with DB2

后端 未结 2 1387
借酒劲吻你
借酒劲吻你 2020-12-21 11:49

I have a python program that calls a stored procedure from db2 database. I am using results = cursor.fetchall() to process the results of my stored procedure. H

相关标签:
2条回答
  • 2020-12-21 12:16

    Use the nextset() method of the cursor: https://github.com/mkleehammer/pyodbc/wiki/Cursor#nextset

    Sample code:

    # fetch rows from first set
    rows = cursor.fetchall()    
    # process first set rows here
    
    # advance to next result set
    while (cursor.nextset()):    
        # fetch rows from next set, discarding first
        rows = cursor.fetchall()    
        # process next set rows here
    

    nextset() will return True if additional result sets are available, and subsequent cursor fetch methods will return rows from the next set. The method returns None if no additional sets are available.

    0 讨论(0)
  • 2020-12-21 12:25

    Just a small simplification for the record:

    while True:    
        rows = cursor.fetchall()
        # process all result sets in the same place
        if not cursor.nextset():
            break    
    
    0 讨论(0)
提交回复
热议问题