Check out the NAME and NAME_uc attributes associated with the statement handle. They essentially give you a hash of column names.
---- Steve Sapovits [EMAIL PROTECTED] > -----Original Message----- > From: Kyle [SMTP:[EMAIL PROTECTED]] > Sent: Monday, September 09, 2002 5:04 PM > To: PERL DBI Users > Subject: getting column names with reply > > Hello > > How can I get SQL to return the column names when doing a select using > the DBI? > > Why do I need this? I am trying to make one sub that will do my various > selects. Right now I'm doing it with discrete subs. I find that these > subs are EXACTLY the same except for parsing the SQL returns by the > appropriate column name. > > Here is a sample of what I'm trying to do (3 requests to the same sub): > > @ArrayOfHashes = sub_get_sql('SELECT * FROM table WHERE trxnum = 100;'); > > @ArrayOfHashes = sub_get_sql("SELECT trxdate FROM table WHERE trxowner = > \'kyle\';"); > > @ArrayOfHashes = sub_get_sql("SELECT trxnum, ordernum, trxowner, > trxinfo, trxdate FROM table WHERE trxnum = \'$trxnum\'"); > > Notice that the columns returned to the sub are different by column > order and the number of columns returned. I can handle the perl parsing > part, but the sub needs to know the column names when they come back. > > Suggestions? > > -Kyle