How to include column headers also with the export

2019-09-22 03:42发布

I was trying to export data from table in DB2 using command..I m abo to export into csv file..But column headers are not there..Need to have column headers as well.So what I can add in the sql query to get column headers as well

1条回答
beautiful°
2楼-- · 2019-09-22 04:06

This is possible in the latest (2019) Db2 11.5 release and Db2 Warehouse (local and on Cloud) with EXTERNAL TABLE feature via INCLUDEHEADER/COLUMN_NAMES switch, see an example

$ db2 "create external table '/home/db2v115/staff.csv' using (delimiter ',' includeheader on) as select * from staff"
DB20000I  The SQL command completed successfully.
$ head /home/db2v115/staff.csv | column -t -s ',' 
ID  NAME      DEPT  JOB    YEARS  SALARY    COMM
10  Sanders   20    Mgr    7      98357.50  
20  Pernal    20    Sales  8      78171.25  612.45
30  Marenghi  38    Mgr    5      77506.75  
40  O'Brien   38    Sales  6      78006.00  846.55
50  Hanes     15    Mgr    10     80659.80  
60  Quigley   38    Sales         66808.30  650.25
70  Rothman   15    Sales  7      76502.83  1152.00
80  James     20    Clerk         43504.60  128.20
90  Koonitz   42    Sales  6      38001.75  1386.70
查看更多
登录 后发表回答