【问题标题】:Export number in tsv from oracle with decimal separator (comma)使用小数分隔符(逗号)从 oracle 导出 tsv 中的数字
【发布时间】:2019-08-15 19:06:16
【问题描述】:

我正在使用python的模块将数据加载到tsv:

cursor = con.cursor()
tsv_file = open(f"{name}.tsv", "w",encoding='UTF-8')
csv.writer(tsv_file, delimiter='\t',quotechar="", lineterminator="\n", quoting=csv.QUOTE_NONE)
r = cursor.execute(f"""select column1, column2, or_num
 from tablename s
""")
writer.writerow([ i[0] for i in cursor.description ]) # heading row
for row in cursor:
    writer.writerow(row)

Oracle中有一个专栏:
但在下载的文件中,数字包含一个点

我试过了: 1) to_char(round(or_num),'9999D999')or_num
结果 - 常规数字,开头有空格,分隔符后有额外的零:
2) to_char(or_num,'9990D99', 'NLS_NUMERIC_CHARACTERS = '',.''')
结果 - 像第一个例子
3) replace(or_num,'.',',')
结果:,8 需要 0,8

我想得到这个结果(将点改为逗号)

【问题讨论】:

  • rtrim(to_char(or_num,'FM9999999D99','NLS_NUMERIC_CHARACTERS='',.'''),',')

标签: python oracle csv export-to-csv separator


【解决方案1】:

要将小数字符设置为逗号并将分组分隔符设置为句点, 在会话级别指定NLS_NUMERIC_CHARACTERS 参数,如下所示:

ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ",."

现在在同一会话中,执行查询以查看下载的 csv 文件中的结果。

干杯!!

【讨论】:

  • 如果你从 PL\sql developer 卸载然后是的,它会用逗号卸载,但我不明白我需要将代码的哪一部分插入到脚本中
  • 你需要在你的python代码中找到答案中提到的查询的执行方式
猜你喜欢
  • 2017-03-06
  • 2014-01-04
  • 2013-08-26
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 2013-02-20
  • 2014-07-16
相关资源
最近更新 更多