selectrow_arrayref can obviously find no rows to return in which case it returns undef:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","yyy");my $r = +$h->selectrow_arrayref("select 1 from dual where 1=0");use Data::Dump +er;print Dumper($r);' $VAR1 = undef;

Unfortunately, selectrow_arrayref also returns undef if there is an error:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","xxx",{RaiseErr +or => 0,PrintError => 0});my $r = $h->selectrow_arrayref("select 1 fr +om dualxx");use Data::Dumper;print Dumper($r);' $VAR1 = undef;

the error being "ORA-00942: table or view does not exist". Note I had to turn off RaiseError and PrintError to a) avoid DBI calling die and b) avoid DBI printing the error. To tell the difference between the two you need to set RaiseError and catch the die:

perl -e 'use DBI;$h = DBI->connect("dbi:Oracle:","xxx","xxx",{RaiseErr +or => 1,PrintError => 0});my $r; eval{$r = $h->selectrow_arrayref("se +lect 1 from dualxx")};if ($@) { print "Error $@ and DBI err is $DBI:: +err";} else {use Data::Dumper;print Dumper($r);}'

which outputs:

Error DBD::Oracle::db selectrow_arrayref failed: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*>; indicator at char 14 in 'select 1 from <*>dualxx') for Statement "select 1 from dualxx" at -e line 1.

In reply to Re: DBI confusion by mje
in thread DBI confusion by PerlRob

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.