How to include column headers also with the export result in IBM DB2

假装没事ソ 提交于 2019-12-25 18:17:46

问题


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:


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


来源:https://stackoverflow.com/questions/57215055/how-to-include-column-headers-also-with-the-export-result-in-ibm-db2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!