Vijay
Vijay

Reputation: 67221

Perl -check for uninitialized value

I am doing the below in a perl script:

my @pm1_CS_missing_months = `sqlplus -s $connstr \@DLmissing_months.sql`;

it takes the output of an sql query. if i have to check for no rows selected,how could i do it? i want to do like this:

if(no rows selected)
{
do this;
}

Upvotes: 1

Views: 1410

Answers (3)

MariusM
MariusM

Reputation: 365

Basically if you are using sqlplus, your output will depend on query. E.g., if there are no rows matching your criteria and you are doing SELECT COUNT(*) FROM TABLE, you will get 0 in the output. If you are doing SELECT * FROM TABLE you will just get answer "no rows selected" which is not an empty output. So it's not enough to check if output is empty or zero, check also if there is string "no rows selected", too.

Upvotes: 0

FMc
FMc

Reputation: 42411

In scalar context (for example, in an if or unless condition), an array evaluates to the number of items in the array. If your SQL result set contains no rows, the array will evaluate to 0 -- one flavor of falseness.

unless (@pm1_CS_missing_months){
   # No rows: do this...
}

Upvotes: 3

René Nyffenegger
René Nyffenegger

Reputation: 40499

I'd go with DBD::Oracle.

Upvotes: 2

Related Questions