Hi Monks,

I tried to retrieve only one column from db every time and combine each time result into an array.

I know I can use "selectcol_arrayref" to do this job, and it works.

However, I kind of doubt its performance. I tried to use a statement handle with a place holder to do it. so I can prepare a query first, and each loop of execute will return all the rows of one single column.

Just didn't find such info anywhere.

could someone give me some hints? thank you.
foreach $id (@id){ $statement = qq{select val1 from tb11 where x=$id}; $col_ref = $dbh->selectcol_arrayref($statement); push @ary,$col_ref; }

above is what I did, which actually just return the values of one column.

now, I want to put the query statement out of the loop,

and use something like $sth->prepare(qq{select val1 from tbl1 where x= ?}),

then in the loop try to do $sth->execute($id) to get the value.

But I want to get the whole column values at once, not just reference to array of reference.

I am wondering if there is a function for statement handle to return all the values for a single column by just one call.

In reply to How to use Perl DBI to select just on column of db by lightoverhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.