【问题标题】:How to populate Csv file with output of SQL in unix如何在 unix 中使用 SQL 的输出填充 Csv 文件
【发布时间】:2014-09-10 08:57:53
【问题描述】:

如何在 unix 中使用 SQL 查询的输出填充 Csv 文件

我所做的是

#! /bin/ksh

echo ",A,B,C\n D\n E">abc.csv

sqlplus -s scott/tiger@host<< EOF >> abc.csv

SET COLSEP ","

SET HEADING OFF

select   count(a1)  from tab1 where condition group by clause;

select   count(b1)  from tab1 where condition group by clause;

exit

EOF

uuencode abc.csv abc.csv | mailx -s "Output" email@id.com

输出

           a  b   c

d 

e


result q1

{a1

b1

c1}

result q2

{

A

B

C

}

期望的输出

      a  b  c

d     a1 b1 c1

e     A   B   C

我如何获得所需的输出 如果我必须在“c”(列标题)之后添加一个“总计”列,需要做什么

【问题讨论】:

  • sqlplus 是甲骨文。你确定你使用 mysql 因为你的问题被标记了?
  • 它的#oracle 是我的错误

标签: sql oracle shell unix csv


【解决方案1】:

经历了很多,我发现SET COLSEP ","出了问题。

所以我所做的是,我将整个脚本替换为:

sqlplus -s scott/tiger@host<< EOF >/dev/null

SET HEAD OFF FEEDBACK OFF

SET LINES 100

SET PAGES 0

spool abc.csv

select  a||','||b||','|| count(a1)  from tab1 where condition group by clause;

spool off

EOF

【讨论】:

    猜你喜欢
    • 2016-04-13
    • 1970-01-01
    • 2020-07-30
    • 2017-04-17
    • 2018-06-30
    • 2019-06-11
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多