python - Python - cx_Oracle - 返回 ORA-01847:月份中的某天必须介于 1 和该月的最后一天之间
问题描述
我很想使用 python cx_Oracle 模块连接到 Oracle 数据库。当我尝试执行特定查询时,我得到“ORA-01847:一个月中的一天必须在一个月的 1 和最后一天之间”
询问:
select case when to_date (STOP_DATE, 'dd-mon-yy')='01-JAN-01' then '000000' else to_char(to_date(STOP_DATE,'dd-mon-yy'),'mmddyy') end STOP_DATE
from table1 where SYS_1= 1234 and rownum < 11
相同的查询在 sqlDeveloper 中运行良好。
非常感谢任何帮助。
Python代码:
import cx_Oracle
connection = None
try:
dsn_tns = cx_Oracle.makedsn("host", "port", service_name="serviceName")
connection = cx_Oracle.connect(user="user", password="password", dsn=dsn_tns)
c = connection.cursor()
sqlStatement = r'''
select case when to_date (STOP_DATE, 'dd-mon-yy')='01-JAN-01' then '000000' else to_char(to_date(STOP_DATE,'dd-mon-yy'),'mmddyy') end STOP_DATE
from table1 where SYS_1= 1234 and rownum < 11
'''
c.execute(sqlStatement)
resultSet = c.fetchall()
if not len(resultSet) == 0:
print("query successful!!!!!!!!!!")
for row in resultSet:
for items in row:
if items == None:
items = ""
print (items)
if connection:
print('all executed')
connection.close()
except Exception as e:
print(e)
if connection:
connection.close()
解决方案
推荐阅读
- javascript - Javascript - 将字典重新格式化为字典数组
- javascript - javascript double 和 java double 有什么区别
- codeigniter - 如何使用 CODEIGNITER 中的实用程序类备份 MySql 数据库(包括存储过程)
- java - 春季不能接受请求
- c# - 将多维数组从 ajax 传递到 ASP.NET MVC
- android - 尝试设置嵌套对象 - 获取“IllegalArgumentException:无效数据。不支持的类型”
- c# - 使用实体框架将数据保存到数据库
- python - 视图 blog.views.post_list 没有返回 HttpResponse 对象。它返回 None 代替(Django)
- react-native - ReactNative 与 Redux - FlatList scrollToEnd
- three.js - Threejs从数组更改体素不透明度