-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 16 October 2002 20:10, Liu, Jenny wrote:
> The following simple sql statement just try to select a column from a
> table. But if the value is 0 or null, the row will not be printed.
> Is there any way I can make all the rows printed? The col1 is a
> integer data type in table.
> Thanks
>
>
> $Sql_stmt = "select col1 from jenny ";
> my $sth_1 = $dbh->prepare($Sql_stmt);
> $sth_1->execute;
> while( $col1 = $sth_1->fetchrow_array){
> print qq($col1 ** \n);
> }
Your code will exit the while loop when a sole NULL or zero is received.
Both zero and NULL are false in Perl's view, so the evaluation will
return false. Receiving a zero or NULL is equivalent of
while ($coll = (0))
or
while ($coll = (undef))
You have to trick the database into returning a true value by selecting
multiple columns like "select 1, coll from jenny".
Other, and more elegant, solution would be to use fetchrow_arrayref()
method. $coll would only evaluate to false when there are no more rows
to fetch.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9raGPnksV4Ys/z5gRAqX/AJ9AQk8Fqs+lMzukufglvaDON9rADQCcCsGy
yS4n5mS9EFEXDq4TsuE74nw=
=dHFx
-----END PGP SIGNATURE-----