Post by Mark AOthers have given the SQL to get the columns names, but I would add an order
by in the SQL query just to make sure you get them in the right order.
The DB2 Catalog tables are described in the appendix of the SQL Reference
Manual, Volume 1. DB2 manuals in PDF format can be downloaded for free from
the IBM web site.
Thank you all for the replies. I have one question regarding to 'order
by' as suggested by Mark. The app will display column names and their
values side by side, which means the order have to be exactly the
same. But I will have two SELECT statements, one to get the column
names, and the other to get their values. How can I make sure the
order will be the same for the two SELECTs? For example, the column
names are:
inst_num, creation_date, last_modified_date, A1, A2, B1, B2, C1, C2,
A3, A4, D1, D2, ...
If I use the following statement:
select colname from syscat.columns where tabname='ops' order by
colname
the column names will be selected in the following order:
A1, A2, A3, A4, B1, B2, C1, C2, creation_date, D1, D2, inst_num,
last_modified_date ...
But the values for those columns will still be corresponding to the
order shown in the first case, if I use the following for the 2nd
SELECT:
select * from ops where inst_num = 1;
the 1st value will be 1, instead of A1, the 2nd value will be
2003-07-09-17.36.53.319908, instead of A2, and so on. How should I
order these two SELECTs in this case? I assume there is no way to
order the 2nd SELECT, which is to get a row of data? I know one way to
resolve it is to order the column names now, when I'm still creating
the database. But if later I need to add columns to that table, the
column names will not be in order again. Another way is not to order
the 1st SELECT, but will I be guaranteed that the column names will be
selected in the order when they were created? It seems so after a few
tests, but I'm not sure if it will always work. If I use SQLDA in the
app for the retrieved data, I cannot order them in the code, either,
or can I?
Thanks,
Minjie