Question & Answer
Question
Can a delimited output from a select statement be generated when using the DB2 command line for the query?
Cause
Sometimes it is desirable to obtain output from a Tivoli Storage Manager database table in a delimited format.
Answer
When a delimited output is needed from a select statement issued via the db2 command line window, the EXPORT TO clause can be used to export the data to an output file in a delimited format. By default, commas are used to delimit the data fields and the data values are enclosed within double quote marks.
In the following example, all fields from the syscat.dbauth table are exported to a file named 'c:\results2.csv'.
| db2 "EXPORT TO c:\result2.csv of del select * from syscat.dbauth" The results2.csv file output will look like the following. "SYSIBM ","S","ADMIN1234","U","Y","Y","Y","Y","Y","Y","Y","Y","Y","N","N" "SYSIBM ","S","SYSTEM ","U","Y","Y","Y","Y","Y","Y","Y","Y","Y","N","N" In this example, only two fields from the syscat.dbauth table are queried. db2 "EXPORT TO c:\result52.csv of del select grantee,securityadmauth from syscat.dbauth" The 'results52.csv' file will look like the following. |
"SYSTEM ","N"
Product Synonym
TSM
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
swg21570170