In cx_Oracle (or Oracle in general), is it possible to allocate a cursor for each query, or to reuse a cursor across several queries.
def getSomeData(curs): # case 1: pass in a cursor, which is generally
curs.execute('select ...') # reused across queries
return curs.fetchall()
def getSomeData(conn): # case 2: pass in a connection,allocate
curs=conn.cursor() # a cursor for this query
curs.execute('select ...')
return curs.fetchall()
Of course, both approaches return the same data.
What are the tradeoffs between the two approaches? Is one particularly more or less efficient? Are there any potential pitfalls to reusing a cursor over many queries?