简体   繁体   中英

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. Can someone help me with an SQL script which can store the results in an CSV file. I'm using db2 database.

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

do and sql create table :

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

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. It's free and open source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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