Reputation: 67221
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
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
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