【问题标题】:How do I fix the formatting in my spooled csv file in sql*plus如何在 sql*plus 中修复我的假脱机 csv 文件中的格式
【发布时间】:2021-07-30 09:05:11
【问题描述】:

我正在使用以下脚本将 sql 查询的输出假脱机到 csv 文件。该查询从视图中提取数据。我的sql*plus版本是12.1.0.2.0

set colsep ,
set headsep off
set pagesize 0
set trimspool on
set NULL ' '
spool myfile.csv
select * from my_view;
spool off

该表有几列具有空值,我需要生成如下所示的输出。

12345,,,ABC,01-JAN-2020

但我的实际输出是这样的。

    12345


A B C   ,01-JAN-2020

为什么所有这些空格都出现在列数据之间?对于空值,插入新行并且缺少逗号。 我该如何解决这个问题?

【问题讨论】:

  • spool myfile.csv之前添加这个:set markup csv on

标签: sql csv sqlplus spool


【解决方案1】:

我修改了 select * 语句如下以获得所需的输出。

select ColA||','||ColB||','||ColC||','||ColD||','||ColE from my_view;

仍然出于好奇,我想知道是否还有其他方法可以达到同样的效果。 同样使用上面的查询会弄乱标题。

【讨论】:

    猜你喜欢
    • 2019-04-22
    • 2011-02-03
    • 2020-07-02
    • 2013-08-01
    • 2012-07-30
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    相关资源
    最近更新 更多