title: Perl and DBD::Oracle - how many rows available to fetch? RowsInCache?
body: <p>I have a perl application that executes a SELECT against an Oracle database using DBD::Oracle.</p>
  
  <p>I'd then like to check if any rows were returned, and branch based on that.</p>
  
  <p>DBD::Oracle's rows() method returns -1 for SELECTs (according the perldoc and my testing), so what I'd do for MySQL won't work.</p>
  
  <p>The perldoc mentions RowsInCache ("Returns the number of un-fetched rows in the cache for selects"), but trying to call or examine that from either my database or statement handle doesn't work.  E.g.:</p>
  
  <pre><code>if ( $sth-&gt;RowsInCache &gt; 0 )
  if ( $sth::RowsInCache &gt; 0 ) 
  if ( $dbh-&gt;RowsInCache &gt; 0 )
  if ( $dbh::RowsInCache &gt; 0 )
  </code></pre>
  
  <p>I get either "Can't locate object method" or "Use of uninitialized value".  Wrong syntax on my part?</p>
  
  <p>I'm aware of a couple ways off accomplishing what I want:</p>
  
  <ol>
  <li><p>First do a SELECT COUNT, look at the number of rows, and then do the real SELECT.  But this is obviously extra work for the DB.</p></li>
  <li><p>If you call</p>
  
  <p>$row = $sth->fetchrow_hashref;</p></li>
  </ol>
  
  <p>Then $row will be undefined if there are no rows and you can test that.  But then if your intent is something like this...</p>
  
  <pre><code>$sth-&gt;execute($some_bind);
  while ( $row = $sth-&gt;fetchrow_hashref ) {
  </code></pre>
  
  <p>...you have to either include some goofy logic to handle the fact that you've already fetched the first row to test if there are rows, or do something like this:</p>
  
  <pre><code>$sth-&gt;execute($some_bind);
  $got_some_rows = 0;
  while ( $row = $sth-&gt;fetchrow_hashref ) {
      $got_some_rows = 1;
      # other stuff
  }
  $sth-&gt;finish;
  if ( $got_some_rows == 0 ) {
  </code></pre>
  
  <p>...which is not the end of the world but....if just seems like there should be some easy way to say "hey database, do you have any rows for me"?</p>
  
  <p>Am I missing something obvious?</p>
  
  <p>Thanks!</p>