This has been driving me crazy for days.
The below SQL string when printed and pasted into SQL Plus works lovely,
yet fails when attempted to run via PERL.
Oh yeah and it fails quietly, no errors, no warnings.

I tried this:

my $query = <<"SQL"; insert into swma_temp_table (m_serial,m_start,m_end,m_stat,m_product) select '$serialno',to_date('$row->[5]', 'YYYY-MM-DD'),to_date('$row->[ +6]', 'YYYY-MM-DD'),'$row->[17]','$row->[9]' from dual where exists (select NULL from servers where host_serial='$serialno') SQL my $rv = $dbh->do($query) or die "prepare failed: " . $dbh->errstr(); #print $query.";\n -- \n";

I also tried this:

my $query = <<"SQL"; insert into swma_temp_table (m_serial,m_start,m_end,m_stat,m_product) select '$serialno',to_date('$row->[5]', 'YYYY-MM-DD'),to_date('$row->[ +6]', 'YYYY-MM-DD'),'$row->[17]','$row->[9]' from dual where exists (select NULL from servers where host_serial='$serialno') SQL my $stmt = $dbh->prepare($query) or die "prepare failed: " . $dbh->errstr(); $stmt->execute() or die "That serial number is not in our database +: " . $stmt->errstr(); #print $query.";\n -- \n";

if your curious here is my connect statement:

my $dbh = DBI->connect("dbi:Oracle:host=superdb;sid=ora46t;port=1522", + 'nunya','beezwax') or die ("connect failed: " . $DBI::errstr. "\n"); $dbh->{AutoCommit} = 1; $dbh->{PrintError} = 1; $dbh->{RaiseError} = 0; $dbh->{ora_check_sql} = 1; $dbh->{RowCacheSize} = 16;

Thanks

The variables in the above query get populated from a CSV file.
Here is some sample output when I enable the print command:

insert into swma_temp_table (m_serial,m_start,m_end,m_stat,m_product) select '10-1D48H',to_date('2009-09-21', 'YYYY-MM-DD'),to_date('2011-07 +-31', 'YYYY-MM-DD'),'Active','694275P' from dual where exists (select NULL from servers where host_serial='10-1D48H') ; -- insert into swma_temp_table (m_serial,m_start,m_end,m_stat,m_product) select '10-2D65H',to_date('2008-04-25', 'YYYY-MM-DD'),to_date('2011-07 +-31', 'YYYY-MM-DD'),'Active','694273H' from dual where exists (select NULL from servers where host_serial='10-2D65H') ; -- insert into swma_temp_table (m_serial,m_start,m_end,m_stat,m_product) select '10-2D65H',to_date('2008-04-25', 'YYYY-MM-DD'),to_date('2011-07 +-31', 'YYYY-MM-DD'),'Active','694275O' from dual where exists (select NULL from servers where host_serial='10-2D65H') ;


In reply to Oracle Insert with DBI by simply seth

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.