python - cx_Oracle 是否允许您强制所有列均为 cx_Oracle.STRING?
这是一小段 Python 代码(不是全部),用于将结果写入文件。但是因为我正在查询的表有一些带有本地时区数据类型的 TIMESTAMP(6),所以该文件以不同的格式存储值,即“2000-5-15 0.59.8.843679000”而不是“15-MAY-00” 10.59.08.843679000 上午'。有没有办法强制它像数据类型是 VARCHAR 一样写入文件(即 cx_Oracle.STRING 或其他方式,以便文件具有与通过客户端工具查询相同的内容)?
db = cx_Oracle.connect(..<MY CONNECT STRING>.)
cursor = db.cursor()
file = open('C:/blah.csv', "w")
r = cursor.execute(<MY SQL>)
for row in cursor:
writer.writerow(row)
This is a small snippet of python code (not the entire thing) to write results to a file. But because my table that I'm querying has some TIMESTAMP(6) WITH LOCAL TIME ZONE datatypes, the file is storing the values in a different format ie '2000-5-15 0.59.8.843679000' instead of '15-MAY-00 10.59.08.843679000 AM'. Is there a way to force it to write to the file as if the datatype were a VARCHAR (ie cx_Oracle.STRING or otherwise so that the file has the same content as querying through a client tool)?
db = cx_Oracle.connect(..<MY CONNECT STRING>.)
cursor = db.cursor()
file = open('C:/blah.csv', "w")
r = cursor.execute(<MY SQL>)
for row in cursor:
writer.writerow(row)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在查询中使用to_char吗?这样它将被强制为 STRING 类型。
Could you use to_char inside your query? That way it will be forced to STRING type.