导出数据以及相应的列名? [英] Export data as well as the corresponding column names?

查看:78
本文介绍了导出数据以及相应的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

有没有办法从某些表中导出数据,以及他们的

对应的列名?我知道我可以使用出口命令导出

从表到DEL文件的数据(用户需要能够直接读取文件
,这样才能选择DEL文件) ,但只有

数据将存在于文件中。用户希望看到列名和

并列数据。我想知道是否有一种简单的方法可以在没有太多编码的情况下这样做。

谢谢。

Hello,
Is there a way to export the data from some tables, along with their
corresponding column names? I know I can use "export" command to export
the data from a table to a DEL file (the users need to be able to read
the file directly, which leaves the choice of a DEL file), but only the
data will be in the file. The users would like to see the column names
side by side with the data as well. I wonder if there is an easy way to
do so without too much coding.
Thanks.

推荐答案

使用ixf格式会有表DDL,包括列名。但不是

直接可读。

简单的方法是这样的

1. db2导出到tablename.del

2. db2 select from tablename> column.del

3. copy column.del + tablename.del


mjf写道:
Use ixf format will have table DDL, include the column name. But not
readable directly.
The easy way is like this
1. db2 export to tablename.del
2. db2 select from tablename > column.del
3. copy column.del + tablename.del

mjf wrote:
你好,
有没有办法从一些表中导出数据,以及它们相应的列名?我知道我可以使用出口命令将表中的数据导出到DEL文件(用户需要能够直接读取文件,这样才能选择DEL文件),但只有
数据将在文件中。用户希望列表名称与数据并排显示。我想知道是否有一种简单的方法可以在没有太多编码的情况下这样做。
谢谢。
Hello,
Is there a way to export the data from some tables, along with their
corresponding column names? I know I can use "export" command to export
the data from a table to a DEL file (the users need to be able to read
the file directly, which leaves the choice of a DEL file), but only the
data will be in the file. The users would like to see the column names
side by side with the data as well. I wonder if there is an easy way to
do so without too much coding.
Thanks.






你可能能够使用UNION查询选择

顶部的COLUMN名称。


SELECT''Column1'',''Column 2'',第3栏''....

UNION ALL

选择......


B.

You may be able to use a UNION query that SELECTs the COLUMN names on
top.

SELECT ''Column1'', ''Column 2'', Column 3''....
UNION ALL
SELECT ......

B.


Hello Brian,你建议的方法很有前途。非常感谢!

我做了一个具有以下DDL的测试表:


db2" describe table test"


列类型类型

名称模式名称长度

规模空值

----------- ------------------- --------- ------------------ ---- ----

----- ------

COL1 SYSIBM SMALLINT 2

0是

COL2 SYSIBM VARCHAR 5

0是

COL3 SYSIBM VARCHAR 5

0是


db2" export to test.del of del modified by chardel''''coldel; decpt,

选择col1,'col1'',col2,''col2'',col3,'col3''来自测试"


导出成功了,这里是test.del中的内容:

1;''col1'';''test1'';''col2'';''val1'';'' col3''

2;''col1'';''test2'';''col2'';''val2'';''col3''

3;''col1'';''test3'';''col2'';''val3'';''col3''


我在列中添加了空格名称,这样用户可以轻松地发现每一对

的值/列名。当

表中有很多列时,上面的内容将会转到下一行,但很难读取
。你知道如何格式化它吗?


1;''col1'';

''test1'';''col2' ';

''val1'';''col3''


2;''col1'';

' 'test2'';''col2'';

''val2'';''col3''


3;''col1'';

''test3'';

''col2'';

''val3'';''col3''

我需要设置每日cron作业来做这样的文件,所以我需要自动完成

所有内容。我想我总是可以写一个PERL脚本给

分开对子,但是想知道是否还有另一种简单的方法可以做到这一点

吧。

再次感谢。

Hello Brian, the method you suggested is very promising. Thanks a lot!
I did it to a test table that has the following DDL:

db2 "describe table test"

Column Type Type
name schema name Length
Scale Nulls
------------------------------ --------- ------------------ --------
----- ------
COL1 SYSIBM SMALLINT 2
0 Yes
COL2 SYSIBM VARCHAR 5
0 Yes
COL3 SYSIBM VARCHAR 5
0 Yes

db2 "export to test.del of del modified by chardel'''' coldel; decpt,
select col1, ''col1 '', col2, ''col2 '', col3, ''col3 '' from test"

The export was successful, and here is the content in test.del:
1;''col1 '';''test1'';''col2 '';''val1'';''col3 ''
2;''col1 '';''test2'';''col2 '';''val2'';''col3 ''
3;''col1 '';''test3'';''col2 '';''val3'';''col3 ''

I added the blanks in the column names so the users can spot each pair
of value/column-name easily. When there are lots of columns in the
table, the above would wrap around to next lines and made it hard to
read, though. Do you know any way of formatting it like the following?

1;''col1 '';
''test1'';''col2 '';
''val1'';''col3 ''

2;''col1 '';
''test2'';''col2 '';
''val2'';''col3 ''

3;''col1 '';
''test3'';
''col2 '';
''val3'';''col3 ''
I need to set up a daily cron job to do such a file, so I need to do
everything automatically. I guess I can always write a PERL script to
separate the pairs, but wonder if there is yet another easy way to do
it.
Thanks again.


这篇关于导出数据以及相应的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆