简体   繁体   English

如何使用DB2数据库将SQL结果从SQL脚本导出为CSV?

[英]How to export SQL results to CSV from an SQL script using DB2 database?

I want to store my Query results in an csv outfile using SQL script. 我想使用SQL脚本将查询结果存储在csv输出文件中。 Can someone help me with an SQL script which can store the results in an CSV file. 有人可以帮我一个可以将结果存储在CSV文件中的SQL脚本吗? I'm using db2 database. 我正在使用db2数据库。

Thanks in advance! 提前致谢!

if you are on iseries (older name AS400), you can use CPYTOIMPF and specify the TOSTMF option to place a CSV file on the IFS directory 如果您在岛上(旧名称为AS400),则可以使用CPYTOIMPF并指定TOSTMF选项以将CSV文件放置在IFS目录中

do and sql create table : 做和SQL创建表:

create table yourlib/yourfile as (  ---- your query ----) with data

like this : 像这样 :

CPYTOIMPF FROMFILE(yourlib/yourfile ) TOSTMF('/outputfile.csv') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)

you can use this command into script sql like this 您可以像这样在脚本sql中使用此命令

CL: CPYTOIMPF FROMFILE(yourlib/yourfile ) TOSTMF('/outputfile.csv') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)

I suggest you just use a database client. 我建议您只使用数据库客户端。 If it's possible in your case of course. 当然,如果可能的话。 For example SQuirreL SQL Client has an ability to export SQL result as CSV, Excel spreadsheet or XML. 例如, SQuirreL SQL Client可以将SQL结果导出为CSV,Excel电子表格或XML。 It's free and open source 它是免费和开源的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM