Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting result of select statement to CSV format in DB2

Tags:

export

csv

db2

Is there any way by which we can export the result of a select statment to CSV file, just like in MySQL.

MySQL Command;

SELECT col1,col2,coln into OUTFILE  'result.csv'  FIELDS TERMINATED BY ',' FROM testtable t; 
like image 780
Rakesh Juyal Avatar asked Jun 29 '09 13:06

Rakesh Juyal


People also ask

Which command will help to create the result to CSV?

Description. The Export-CSV cmdlet creates a CSV file of the objects that you submit. Each object is a row that includes a comma-separated list of the object's property values. You can use the Export-CSV cmdlet to create spreadsheets and share data with programs that accept CSV files as input.


1 Answers

You can run this command from the DB2 command line processor (CLP) or from inside a SQL application by calling the ADMIN_CMD stored procedure

EXPORT TO result.csv OF DEL MODIFIED BY NOCHARDEL  SELECT col1, col2, coln FROM testtable; 

There are lots of options for IMPORT and EXPORT that you can use to create a data file that meets your needs. The NOCHARDEL qualifier will suppress double quote characters that would otherwise appear around each character column.

Keep in mind that any SELECT statement can be used as the source for your export, including joins or even recursive SQL. The export utility will also honor the sort order if you specify an ORDER BY in your SELECT statement.

like image 190
Fred Sobotka Avatar answered Oct 11 '22 18:10

Fred Sobotka