set_uk has asked for the wisdom of the Perl Monks concerning the following question:

What is the preferred way of inserting dates into an Oracle DATE column using Class DBI Oracle. I would use SYSDATE but cant make it work. Is it down to the perl script to format the date - does it need the Oracle TO_DATE format? Thanks

Replies are listed 'Best First'.
Re: Class::DBI Oracle Dates
by freddo411 (Chaplain) on Oct 28, 2003 at 21:56 UTC
    I haven't tried to set dates with Class::DBI yet, but I will be working that issue shortly on my current project. I've already run into some Oracle specific problems, where I needed to write some custom SQL, so don't be surprized at this. (The custom SQL was for "paging").

    In a prior project I used DBI by itself. I ended up writing a single routine to handle writing any generalized data into my tables. Part of the routine handling oracle SQL generation for dates looked like this:

    # Note that date data must consist of a date encased in # single quotes followed by a comma, then a date # format string encased in single quotes. For example: # '2002-05-30','YYYY-MM-DD' # or '05/30/2000:18:31','MM/DD/YYYY:HH:MM' foreach $name ( keys (%$r_datedata) ) { $column_str .= $name . ", "; if ( $$r_datedata{$name} eq "SYSDATE" ) { $value_str .= "SYSDATE, "; } else { $value_str .= "to_date(" . $$r_datedata{$name} . "), "; } }
    I imagine you'll need to do something similar.

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

      Got it working with Class DBI - had to revert to Ima::DBI set_sql in the dbi subclass against the table. Code in the subclass
      SDU::DBI_AJ->set_sql('InsertInfoAJ', 'INSERT into sdu_active_jobs(jobid,job_name,target_device,customer, + start_date,status) VALUES (?,?,?,?,SYSDATE,?)','Main');
      Code in the calling class:-
      $create_job = SDU::DBI_AJ->sql_InsertInfoAJ; $rv = $create_job->execute($cr{jobid}, $cr{job_name}, $cr{target_device}, $cr{customer}, $cr{status});
      This seems too complex - for just wanting to use sysdate.
Re: Class::DBI Oracle Dates
by Plankton (Vicar) on Oct 28, 2003 at 21:32 UTC
    Maybe this node will answer your question.

    Plankton: 1% Evil, 99% Hot Gas.
      Not bad. I can do it in straight Oracle - but trying to work it through Class::DBI isn't as straightforward. I'm trying to avoid writing a specific Ima::DBI statement. I'm sure others have solved this already