Well I see you couldn't come up a situation where select * is better than the more explict select col_a, col_b, ... so I will provide you with one. This script , given a table name, creates control files for Oracle's sqlldr.
... my $SQL = <<SQL; Select * from $table SQL $dbh->{LongReadLen} = 65500; my $sth = $dbh->prepare($SQL) || die $dbh->errstr; $sth->execute(); my $colNames = $sth->{'NAME'}; my $nColumns = $sth->{'NUM_OF_FIELDS'}; my $colString; for my $colName ( @$colNames ) { $colString .= "\n\t$colName,"; } chop($colString); print <<DOIT; OPTIONS (ROWS=1) LOAD DATA INFILE * REPLACE INTO TABLE $table FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( DOIT print "$colString\n"; print<<DOIT; ) BEGINDATA DOIT while ( my @r = $sth->fetchrow_array ) { print join ( '|', map ( $_ , trim( @r )) ); print "\n"; } $sth->finish || die; $dbh->disconnect; ...
Would your solution to this be have huge if/elsif statement that would have a different $SQL string for each table in the database?
# can't use select * so ... if ( $table eq "MY_FIRST_TABLE" ) { $SQL = "select blah_1, blah_2 from MY_FIRST_TABLE"; } elsif ( $table eq "MY_2ND_TABLE" ) { $SQL = "select another_col, dob from MY_2ND_TABLE"; } ...
Or would you choose to access the database twice, once to do your describe table (which BTW is not portable to other DBMSs) and a second time to get the data from the table? Why not just access the database once?

Plankton: 1% Evil, 99% Hot Gas.

In reply to Re: Re: Re: Re: selecting again from a mysql database by Plankton
in thread selecting again from a mysql database by bory

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.