Here's how I do it.  This way you don't have to keep track of which 
field(s) may be null.


my $slct_insp = $dbh->prepare("select * from tqosinsptrk
                                where chgdttm < current - 10 units minute
                                  and procdttm is null order by insptrkrwd asc") || 
die cleanup("prepare select tqosinsptrk");

undef $rv;
undef $ref;
$rv = $slct_insp->execute || die cleanup("execute select tqosinsptrk");
$ref = $slct_insp->fetchall_arrayref() || die cleanup("fetchall select tqosinspt
rk");

open(OUT,">$dtafile2") || die cleanup("open insp outfile");
foreach my $row (@$ref) {
   $out = join("|",map { chkinit($_) } @$row) || die cleanup("join insp");
   print OUT $out,"|\n" || die cleanup("print insp outfile");
   $upd_insp->execute(@$row[0]) || die cleanup("execute update insptrk");
   }
close(OUT) || die cleanup("close insp file");

##########################################################################
# SUBROUTINE: CHKINIT                                                    #
##########################################################################
sub chkinit {
my ($fld) =@_;

if ( ! defined $fld ) {
   $fld='';
   }

return $fld;

}


> 
> But if what you want to get (and print) is "", would this (using NVL
> in the select statement) work? Or would "" returned from the database
> get interpreted by the DBI (or maybe by Perl itself) as undef?
> 
> Here's my clunky workaround for avoiding warnings about undef values (when
> I don't want to just say "no warnings 'uninitialized';" in that block):
> 
> while ( $sth->fetch )
> {
>    for my $each ( $field1, $field2 ) #-- any fields I'm fetching that might be null
>    {
>       $each ||= "";
>    }
>    print OUT join "|", ( $field1, $field2, $field3 ), "\n";
> }
> 
> Mitch Helle-Morrissey's idea seems much more elegant.
> 
> -- 
> David Dierauer
> Database Programmer
> CoreComm
> 
> On Fri, 4 Jan 2002, Morris Paterson wrote:
> 
> > why not use a NVL in your select staetment?
> >
> > Mitch Helle-Morrissey wrote:
> >
> > > Is there any way to have DBI return NULL database values as something other
> > > than Perl undef?  It's a pain if you're printing out a bunch of columns
> > > without examining the values because printing an undef generates warnings.
> > > I wrote my own function to map undefs to something else, but I was thinking
> > > it would be nice to have an attribute of how NULL database values will be
> > > returned to Perl.  Maybe something like:
> > >
> > >         $dbh->{NULL_VALUE} = '';
> > >         $dbh->{NULL_VALUE} = 'NULL';
> > >         $dbh->{NULL_VALUE} = undef;    # current behavior
> 
> 


--
Internet:             | Paul J. Falbe             |                          
   [EMAIL PROTECTED]  | Cassens Transport         | Std disclaimers apply.   
Voice:                | 145 N. Kansas Str.        |  (But you knew that!)    
   618-656-3006       | Edwardsville, IL 62025    |                          

Reply via email to