how to pass the result set to another oracle sql query in Python

28 views Asked by At

I have the below code and its working fine. i am trying to figure out a way to pass the the result directly to the query instead of in_clause variable.

I tried the below code but its failing with DPY-3002: Python value of type "tuple" is not supported

testQuery="select * from TRX_HDR where hdr_id in (:hdr_ids)"
cursor.execute(testQuery, {'hdr_ids': results})

Complete code

query = "SELECT column_name FROM your_table WHERE your_condition"
cursor.execute(query)
results = cursor.fetchall()
ord_ids = [result[0] for result in results]

# Constructing the IN clause for the second query
in_clause = ', '.join(map(str, ord_ids))


testQuery = f"SELECT * FROM TRX_HDR WHERE hdr_id IN ({in_clause})"
cursor.execute(testQuery)
second_query_results = cursor.fetchall()```
0

There are 0 answers