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.
|