python中与cx_Oracle绑定变量的异常
好的,我已连接到 python 2.7 中的 oracle 数据库,并且 cx_Oracle 5.1 是针对即时客户端 11.2 编译的。我有一个指向数据库的游标,运行 SQL 不是问题,除了这个:
cursor.execute('ALTER TRIGGER :schema_trigger_name DISABLE', schema_trigger_name='test.test_trigger')
或者
cursor.prepare('ALTER TRIGGER :schema_trigger_name DISABLE') cursor.execute(None,{'schema_trigger_name': 'test.test_trigger'})
两者都会导致 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
运行时:
cursor.execute('ALTER TRIGGER test.test_trigger DISABLE')
工作完美。绑定该变量有什么问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的示例中
test.test_trigger
不是变量而是对象。您只能绑定变量(可以用值替换)。您尝试运行的查询在逻辑上相当于:
在这种情况下绑定将不起作用,您必须动态构建查询。
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:
Binding in this case won't work, you will have to build the query dynamically.
通常不能在 Oracle 中绑定对象名称。对于变量它可以工作,但对于trigger_names、table_names等则不起作用。
You normally can't bind an object name in Oracle. For variables it'll work but not for trigger_names, table_names etc.