如何在 IBM DB2 中的导出结果中也包含列标题 [英] How to include column headers also with the export result in IBM DB2
本文介绍了如何在 IBM DB2 中的导出结果中也包含列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用命令从 DB2 中的表中导出数据..我想导出到 csv 文件中..但是列标题不存在..也需要列标题.所以我可以在sql查询也可以获取列标题
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
推荐答案
这在最新 (2019) Db2 11.5 版本和带有 外部表
特性通过 INCLUDEHEADER
/COLUMN_NAMES
开关,看一个例子
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
这篇关于如何在 IBM DB2 中的导出结果中也包含列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文