I am currently trying to bind variables into a SQL Query. I am using the Cx_Oracle Library.
c.execute("""
select employee_id, first_name, last_name, TO_CHAR(hire_date, 'mm/dd/yyyy'), salary from employees
order by 1
""")
This Query work perfectly fine and I get the desired output.
But if I try these two queries, I get the cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
I tried these methods to bind the variables:
tempo = "employees"
test_query = "select employee_id, first_name, last_name, TO_CHAR(hire_date, 'mm/dd/yyyy'), salary from :temp"
c.execute(test_query, temp=tempo)
--> Error I mentioned earlier
The second method:
c.execute("""
select employee_id, first_name, last_name, TO_CHAR(hire_date, 'mm/dd/yyyy'), salary from :table_name
order by 1
""", table_name="employees")
--> cx_Oracle.DatabaseError: ORA-00903: Invalid Table Name
I don't understand, why this binding isn't working, does anyone have a clue? Thanks in advance