I need to execute the following UNION ALL Select statements, I am using bind variables for the WHERE conditions. I am using PyODBC for Oracle. While the code executes and returns results, it takes a lot of time if compared to running it from TOAD directly. Any Ideas what is the problem?
query = """
SELECT concat('Abstract ',display_order), abstract_text as field1,
abstract_source_code, display_order
From abstract
WHERE control_number = ? and control_level = ?
UNION ALL
SELECT 'cTitle', chapter_title, null as col2, null as col3
From chapter
WHERE control_number = ? and control_level = ?
"""
result = cursor.execute(query, ['201728871', '005', '201728871', '005']).fetchall()
print(result)