Whatever your database driver accepts as a valid SQL statement is fine as far as the DBI is concerned. Thus, if Oracle accepts a query like "SELECT COUNT(*) from t1; SELECT COUNT(*) from t2;" so you can do it.
If that is not the case, you can force that behavior with some SQL features:
my $query = qq{
select "t1" as t, count(*) as c from table_one
UNION ALL
select "t2", count(*) from table_two
};
# Gives
# +----+---+
# | t | c |
# +----+---+
# | t1 | 4 |
# | t2 | 2 |
# +----+---+
my $table_status = $dbh->selectall_arrayref($query, {Slice => {}} );
# $table_status = [
# { t => 't1', c => 4 },
# { t => 't2', c => 2 }
# ];
Or:
my $query = qq{
SELECT
( select count(*) from table_one ) AS t1,
( select count(*) from table_two ) AS t2;
};
# Gives
# +----+----+
# | t1 | t2 |
# +----+----+
# | 4 | 2 |
# +----+----+
my @table_status = $dbh->selectrow_array($query);
# @table_status = ( 4, 2 );
I would personally recommend against this, since I prefer to have better control on my SQL statements. However, if you know what you're doing, it's up to you to decide.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.