simply seth has asked for the wisdom of the Perl Monks concerning the following question:
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;
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') ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Oracle Insert with DBI
by SilasTheMonk (Chaplain) on Jan 12, 2010 at 14:51 UTC | |
by simply seth (Initiate) on Jan 12, 2010 at 15:36 UTC | |
|
Re: Oracle Insert with DBI
by almut (Canon) on Jan 12, 2010 at 16:41 UTC | |
by simply seth (Initiate) on Jan 12, 2010 at 17:21 UTC | |
by almut (Canon) on Jan 12, 2010 at 17:31 UTC | |
by mje (Curate) on Jan 12, 2010 at 17:51 UTC | |
|
Re: Oracle Insert with DBI
by mje (Curate) on Jan 12, 2010 at 16:50 UTC | |
by simply seth (Initiate) on Jan 12, 2010 at 17:38 UTC | |
by mje (Curate) on Jan 12, 2010 at 17:47 UTC | |
by simply seth (Initiate) on Jan 12, 2010 at 19:00 UTC | |
by mje (Curate) on Jan 13, 2010 at 09:45 UTC |