Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

 _  _ _  _  
(_|| | |(_|><
 _|   

In reply to Re: prepare statement within DBI by gmax
in thread prepare statement within DBI by Paulster2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found