Exception binding variables with cx_Oracle in python
Okay, so I'm connected to an oracle database in python 2.7 and cx_Oracle 5.1 compiled against the instant client 11.2. I've got a cursor to the database and running SQL is not an issue, except this:
cursor.execute('ALTER TRIGGER :schema_trigger_name DISABLE', schema_trigger_name='test.test_trigger')
or
cursor.prepare('ALTER TRIGGER :schema_trigger_name DISABLE') cursor.execute(None,{'schema_trigger_name': 'test.test_trigger'})
both result in an error from oracle:
Traceback (most recent call last): File "connect.py", line 257, in cursor.execute('ALTER TRIGGER :schema_trigger_name DISABLE', schema_trigger_name='test.test_trigger') cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
While running:
cursor.execute('ALTER TRIGGER test.test_trigger DISABLE')
works perfectly. Wha开发者_StackOverflow社区t's the issue with binding that variable?
In your example test.test_trigger
is not a variable but an object. You can only bind variables (that can be replaced by a value).
The query you are trying to run would be logically equivalent to:
ALTER TRIGGER 'test.test_trigger' DISABLE
Binding in this case won't work, you will have to build the query dynamically.
You normally can't bind an object name in Oracle. For variables it'll work but not for trigger_names, table_names etc.
精彩评论