Domanda

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. What's the issue with binding that variable?

È stato utile?

Soluzione

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.

Altri suggerimenti

You normally can't bind an object name in Oracle. For variables it'll work but not for trigger_names, table_names etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top