2014-09-10 44 views
-1

如何填充CSV文件和SQL查询的输出在UNIX如何填充的CSV文件,SQL的输出在UNIX

文件

我所做的是

#! /bin/ksh 

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

sqlplus -s scott/[email protected]<<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 protected] 

输出

  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”(列标题)

+0

'sqlplus'是甲骨文。你确定你用mysql工作,因为你的问题被标记了吗? – Jens 2014-09-10 09:04:25

+0

其#oracle 这是我的错 – 2014-09-10 09:15:30

回答

0

经过很多事情后后添加一个“总”专栏中,我发现SET COLSEP ","是给问题。

所以我所做的是,我更换整个脚本:

sqlplus -s scott/[email protected]<<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