Adding Column Names to an Unload File

By | In DB2 | August 19th, 2015

Adding Column Names to an Unload FileI received an e-mail from a reader asking an interesting question. She wanted to know if any of the DB2 unload utilities are able to include the column names in the same file as the unload output data. This was a requirement because one of the applications her company was planning to use takes the column headings and dynamically creates tables.

My initial reaction was that she could write a program that takes the output file and reads the system catalog to gather the appropriate column names. That would work, but she actually came up with a better solution.

She used a third party Unload utility (but it would also have worked with IBM’s Unload, too) to perform two SELECT statements. The first just creates the column headers and the second for the actual data. The column names and data go to two separate data sets, but they used IDCAMS to concatenate the 2 separate column/data sets into 1 data set.

The SQL is simple, something like as follows:

Of course, you’d just plug in the correct column names in the literals of the first SELECT statement — and the correct column names in the second.

This post was originally posted on Craig Mullins’ blog.

Craig Mullins
Consultant at Mullins Consulting, Inc
Craig S. Mullins is working with Datavail and its DB2 practice to expand offerings. He is president and principal consultant at Mullins Consulting, Inc. and the publisher of The Database Site. Mullins has 30 years of experience in all facets of database management and is the author of two books: “DB2 Developer’s Guide” currently in its 6th edition and “Database Administration: The Complete Guide to DBA Practices and Procedures,” the industry’s only guide to heterogeneous DBA.

Leave a Reply

Your email address will not be published.
Required fields are marked (*).