I really need the help of the Perl/Oracle gurus out there :( I have this program that is trying to do an insert on a table that has two TIMESTAMP fields. Here's the consolidated code:

use strict; use DBI; $ENV{'ORACLE_HOME'} = '/pkg/oracle/client10g'; my $sid = 'mysid'; my $user = 'joe'; my $pass = 'joespw'; my $dbh = DBI->connect( "dbi:Oracle:$sid", "$user", "$pass" ) || die( $DBI::errstr . "\n" ); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; $dbh->{ora_check_sql} = 0; $dbh->{RowCacheSize} = 16; my $sql = qq{insert into reservation (machinename,reservationida,begin +reserve,endreserve,description,reservationid) values (?,?,TO_TIMESTAM +P(?,'DD/MON/YYYY HH:MI:SS'), TO_TIMESTAMP(?,'DD/MON/YYYY HH.MI.SS'),?,?)}; my $sth = $dbh->prepare($sql); $sth->bind_param(1, 'volcano'); $sth->bind_param(2, 666); $sth->bind_param(3, '12/MAR/2010 7:20:00'); $sth->bind_param(4, '12/MAR/2010 8:20:00'); $sth->bind_param(5, 'This machine tends to explode!'); $sth->bind_param(6, 666); #print "$sql\n"; $sth->execute; $sth->finish; $dbh->disconnect;

The database table:

SQL> Name Null? Type ----------------------------------------- -------- ------------------ +---------- RESERVERNAME VARCHAR2(200) RESERVATIONIDA NOT NULL NUMBER(38) BEGINRESERVE NOT NULL TIMESTAMP(6) ENDRESERVE TIMESTAMP(6) DESCRIPTION VARCHAR2(400) MACHINENAME NOT NULL VARCHAR2(20) RESERVATIONID NOT NULL CHAR(50) SQL> Disconnected from Oracle Database 11g Enterprise Edition Release +11.1.0.6.0 - 64bit Production

Here are 2 normal rows from a select statement:

CARRIE,123454,24-NOV-09 06.00.00.000000 PM,24-NOV-09 08.00.00.000000 P +M,For Carrie test,pipe,123454 box1,56789,25-JUL-09 07.00.00.000000 AM,25-JUL-09 08.00.00.000000 AM,, +ector,56789

When I run my script, I get:

DBD::Oracle::st execute failed: ORA-02291: integrity constraint (LRRS. +RESERVATION_MACHINE_FK1) violated - parent key not found (DBD ERROR: +OCIStmtExecute) [for Statement "insert into reservation (machinename, +reservationida,beginreserve,endreserve,description,reservationid) val +ues (?,?,TO_TIMESTAMP(?,'DD/MON/YYYY HH:MI:SS'),TO_TIMESTAMP(?,'DD/MO +N/YYYY HH.MI.SS'),?,?)" with ParamValues: :p1='volcano', :p2=666, :p3 +='12/MAR/2010 7:20:00', :p4='12/MAR/2010 8:20:00', :p5='This is explo +sive fun!', :p6=666] at ./liltest.pl line 23.

This error actually appears twice.

I can connect using sqlplus and insert manually, kind of like this: http://use.perl.org/~jdavidb/journal/29951, so it seems TO_TIMESTAMP should work - actually I'm not even sure if that's the problem. Can't seem to figure this one out... thanks for the help!
DW


In reply to DBD::Oracle foreign key problem by digdoug

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.