python - cx_oracle python 并选择 Like %variable%
问题描述
我正在尝试基于“tempo”变量执行查询,使用 %tempo% 我在这里找到的解决方案都没有帮助我的问题
import cx_oracle
query="""SELECT description, local, point, date
FROM tbl_ext_tempo
WHERE point like '%' || :0 || '%'
AND ROWNUM < 8
ORDER BY date DESC
"""
cursor.execute(query, tempo)
异常值:
ORA-01036: illegal variable name/number
解决方案
您可以定义一个列表(lst
),并将当前字符串按格式附加到它
lst = []
tempo = 'someValue'
query="""
SELECT description, local, point, "date"
FROM tbl_ext_tempo
WHERE point LIKE :0
AND ROWNUM < 8
ORDER BY "date" DESC
"""
lst.append('%{}%'.format(tempo))
cursor.execute(query,(lst))
print(cursor.fetchall())
date
不能将列名作为保留关键字,也许它可能被"date"
引用。
推荐阅读
- javascript - 更新传入组件的样式 - ReactJS
- python - Python:将 pdf 转换为 csv/json
- javascript - 更改大小文本区域 onCheck
- html - css网格单元格内容溢出不起作用
- node.js - 用于重复调用特定路由的 NodeJS 调度程序
- java - PSDocumentGraphics2D - 我如何编写 <>setpagedevice
- python - PyQt4:如何将一个对象放在另一个对象的前面?
- python - Pandas Dataframe 计算 Num Business Days
- android - 使用 removeView() 从 AppBarLayout 中删除 TabLayout 时出现故障
- javascript - 用Java截取整个网页