python中与cx_Oracle绑定变量的异常

发布于 2024-12-01 01:47:32 字数 844 浏览 2 评论 0原文

好的,我已连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2024-12-08 01:47:32

在您的示例中 test.test_trigger 不是变量而是对象。您只能绑定变量(可以用值替换)。

您尝试运行的查询在逻辑上相当于:

ALTER TRIGGER 'test.test_trigger' DISABLE

在这种情况下绑定将不起作用,您必须动态构建查询。

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.

零度℉ 2024-12-08 01:47:32

通常不能在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文