I have the following subroutine that is supposed to create a SQL stmt on the fly, but it keeps failing with this error: ORA-00972: identifier is too long (DBD ERROR: OCIStmtPrepare) at promo.pl line 933. when it gets to the prepare section, and it prints out the else part of the query when it should not be. I'm stumped.
sub get_BCE_qty { my $num_days_of_supp = shift; my $loc = shift; my $dmdunit = shift; LogMsg("Days of Supply = $num_days_of_supp"); my $qry; my @new_array; my @months_to_sum = ( 12 - ($num_days_of_supp/30) .. 11 ); if ( $num_days_of_supp % 30 == 0 ) { $qry = '"SELECT GREATEST(ROUND((SUM(' . join( ' + ', map { sprintf "mth_%02i", $_ } ( 1 .. 12 ) ) . ") / 365 ) * $num_days_of_supp ), ROUND (SUM (" . join(' + ', map { sprintf "mth_%02i", $_ } @months_to_sum) . '))) QTY, b. p_dlrnet, b.p_dlrsplrcode ' . <<'EOF'; FROM pac.historyreportmonthlybysku a , stsc.sku b WHERE a.loc = ? AND a.dmdunit = ? AND a.loc = b.loc AND a.dmdunit = b.ITEM GROUP BY a.loc , a.dmdunit , b.p_dlrnet , b.p_dlrsplrcode" EOF } else { @new_array = @months_to_sum; shift @new_array; # remove the 1st element since this is the one + we divide by 2 $qry = '"SELECT GREATEST(ROUND((SUM(' . join( ' + ', map { sprintf "mth_%02i", $_ } ( 1 .. 12 ) ) . ") / 365 ) * $num_days_of_supp ), ROUND (SUM (" . sprintf ("mth_%02i", $months_to_sum[0]) . " / 2 + " . join(' + ', map { sprintf "mth_%02i", $_ } @new_array) . '))) QTY, b. p_dlrnet, b.p_dlrsplrcode ' . <<'EOF'; FROM pac.historyreportmonthlybysku a , stsc.sku b WHERE a.loc = ? AND a.dmdunit = ? AND a.loc = b.loc AND a.dmdunit = b.ITEM GROUP BY a.loc , a.dmdunit , b.p_dlrnet , b.p_dlrsplrcode" EOF }; LogMsg($qry); # prepare and execute the query my $sth_C = $dbh->prepare( $qry ) or die $dbh->errstr; + $sth_C->execute( $loc, $dmdunit ); my ($col1, $col2, $col3); $sth_C->bind_col(1, \$col1); $sth_C->bind_col(2, \$col2); $sth_C->bind_col(3, \$col3); $sth_C->fetch(); my $BCE_qty = $col1; my $dlrnet = $col2; my $dlrsupcode = $col3; return $BCE_qty, $dlrnet, $dlrsupcode; }

In reply to Help with Dynamic SQL subroutine by sasrs99

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.