Don't think about this as converting a script line for line. Think about this as transporting functionality. Instead of doing everything in SQL, do some of it in Perl. For example:
my $sql = <<SQL; select sd.site_name, sum(NVL(ncl.downtime_secs,0)) downtime, (case when ? < 100 then to_char(?,99.99999) else to_char(?,999) en +d) availability, convert_seconds_to_dhms(sum(NVL(ncl.downtime_secs,0))) downtime_dh +ms, country from ncl_summary_tmp ncl, (select distinct contracted_node_name, site_name from contracted_n +odes ) cn, site_details sd where UPPER(SUBSTR(ncl.node (+) ,0,(INSTR(ncl.node (+),'.') -1))) = +cn.contracted_node_name and sd.site_name = cn.site_name having ? < 100 group by sd.site_name order by downtime SQL my $sth = $dbh->prepare_cached($sql) || die; $sth->execute(($percent) x 4) || die; $sth->bind_columns(\my ( $sitename, $downtime, $availability, $downtime_dhms, $country, )); my %countries; while ($sth->fetch) { push @{$countries{$country}{values}}, [ $sitename, $downtime, $availability, $downtime_dhms, ]; $countries{$country}{total_downtime} += $downtime; } $sth->finish;
At the end of that snippet, you have a hash, keyed by country with values of the stuff returned as well as the total downtime.

I'm curious as to what more you'd need ...

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re3: Sqlplus -> DBD::Oracle Question by dragonchild
in thread Sqlplus -> DBD::Oracle Question by set_uk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.