简体   繁体   English

Python cx_Oracle用qmark准备的语句

[英]Python cx_Oracle prepared statement with qmark

I am trying to work with cx_Oracle, but it seems to dislike what I know about db-api. 我正在尝试使用cx_Oracle,但似乎不喜欢我对db-api的了解。

These statement work: 这些语句起作用:

cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (2, 123)')
cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (:id, :sid)', 
            {'id':1, 'sid':13})
cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (:1, :2)', [1123, 123])

However, this fails: 但是,这失败了:

cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (?, ?)', [1, 123])

The above fails with: 上面的失败与:

---------------------------------------------------------------------------
DatabaseError                             Traceback (most recent call last)
<ipython-input-17-4e9fe350f968> in <module>()
----> 1 cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (?, ?)', [1, 123])

DatabaseError: ORA-01036: illegal variable name/number

Is there a way to correct this statement? 有没有办法纠正这个说法? Does cx_Oracle suppprt qmark ? cx_Oracle是否支持qmark

Sadly, I found an answer here ... 可悲的是,我在这里找到了答案...

You can't truly choose what paramstyle you would like to use. 您无法真正选择想要使用的paramstyle。 Oracle only natively supports named and numeric paramstyles and cx_Oracle supports both of those. Oracle仅本机支持命名和数字参数样式,而cx_Oracle支持这两种样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM