【问题标题】:How to include column headers also with the export result in IBM DB2如何在 IBM DB2 中的导出结果中也包含列标题
【发布时间】:2019-07-26 07:24:45
【问题描述】:

我试图使用命令从 DB2 中的表中导出数据..我想导出到 csv 文件中..但是列标题不存在..还需要列标题。所以我可以在sql查询也可以获取列标题

【问题讨论】:

标签: sql db2 db2-400 db2-luw


【解决方案1】:

通过INCLUDEHEADER/COLUMN_NAMES 开关,可以在具有EXTERNAL TABLE 功能的最新(2019)Db2 11.5 版本和Db2 Warehouse(本地和云端)中实现这一点,请参阅示例

$ 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

【讨论】:

    猜你喜欢
    • 2019-09-14
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    相关资源
    最近更新 更多