python使用oracle查询数据库,查询语句中使用变量值 30
代码如下:importcx_Oracledefgetdata(Item):conn=cx_Oracle.connect('p00292','pan00292','hsmm...
代码如下:
import cx_Oracle
def getdata(Item):
conn=cx_Oracle.connect('p00292','pan00292','hsmmdb-rac-scan.uniview.com:1521/HSMM')
cursor= conn.cursor()
cursor.execute('select * from INV.MTL_ITEM_REVISIONS where ROW_ID= %s'% (Item,))
fir=cursor.fetchone()
print fir
getdata('AAAdjoAAzAAABL7AAB')
运行python后显示的错误消息如下:
D:\Python27\python.exe D:/python自动化测试/ceshi1.py
Traceback (most recent call last):
File "D:/python自动化测试/ceshi1.py", line 8, in <module>
getdata('AAAdjoAAzAAABL7AAB')
File "D:/python自动化测试/ceshi1.py", line 5, in getdata
cursor.execute('select * from INV.MTL_ITEM_REVISIONS where ROW_ID= %s'% (Item,))
cx_Oracle.DatabaseError: ORA-00904: "AAADJOAAZAAABL7AAB": invalid identifier
请大神们赐教 展开
import cx_Oracle
def getdata(Item):
conn=cx_Oracle.connect('p00292','pan00292','hsmmdb-rac-scan.uniview.com:1521/HSMM')
cursor= conn.cursor()
cursor.execute('select * from INV.MTL_ITEM_REVISIONS where ROW_ID= %s'% (Item,))
fir=cursor.fetchone()
print fir
getdata('AAAdjoAAzAAABL7AAB')
运行python后显示的错误消息如下:
D:\Python27\python.exe D:/python自动化测试/ceshi1.py
Traceback (most recent call last):
File "D:/python自动化测试/ceshi1.py", line 8, in <module>
getdata('AAAdjoAAzAAABL7AAB')
File "D:/python自动化测试/ceshi1.py", line 5, in getdata
cursor.execute('select * from INV.MTL_ITEM_REVISIONS where ROW_ID= %s'% (Item,))
cx_Oracle.DatabaseError: ORA-00904: "AAADJOAAZAAABL7AAB": invalid identifier
请大神们赐教 展开
3个回答
展开全部
cursor.execute('select * from INV.MTL_ITEM_REVISIONS where ROW_ID= %s'% (Item,))
换为:
qry_sql = "select * from INV.MTL_ITEM_REVISIONS where ROW_ID= '%s'" % Item
cursor.execute(qry_sql)
换为:
qry_sql = "select * from INV.MTL_ITEM_REVISIONS where ROW_ID= '%s'" % Item
cursor.execute(qry_sql)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ROWID值的%s 需要单引号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
getdata("'AAAdjoAAzAAABL7AAB'")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询