I use DBI. And I want to make some like

INSERT INTO ... VALUES (the_generated_timestamp, ...);

What is the command? How could it be created, the perl ``ocaltimescalar value has a very complex, for human eyes optimized format (f.e.Mon Apr 28 15:58:51 2014). My goal were some like as the unixgettimeofday()` does (giving back the seconds since 1970.1.1), converted by some format string, which I can let eat by the Oracle.

But any simpler solution were also okay, if it exists.

It need to be generated in perl. INSERT ... (current_timestamp, ...) isn't okay.

  • Are you maybe looking for current_timestamp? INSERT INTO ... VALUES (current_timestamp, ...); – a_horse_with_no_name Apr 28 '14 at 14:16
  • @a_horse_with_no_name Thank you, but I need to generate it in Perl. – peterh - Reinstate Monica Apr 28 '14 at 14:16
  • 1
    The generate the date as a string in e.g. ISO format, and use to_date() or to_timestamp() – a_horse_with_no_name Apr 28 '14 at 14:17
  • You can use TO_TIMESTAMP or to_timestamp_tz Oracle functions that convert string to timestamp . INSERT ... VALUES(TO_TIMESTAMP('string', 'format'), .... – a1ex07 Apr 28 '14 at 15:34

Something like this will do:

my ($second, $minute, $hour, $day, $month, $year, $weekday, $dayofyear, $dst) = localtime();

my $oracledatestring = sprintf "TO_DATE('%04d/%02d/%02d %02d:%02d:%02d', 'yyyymmdd HH24:MI:SS')", $year+1900, $month+1, $day, $hour, $minute, $second;

.. giving something like:

TO_DATE('2014/04/28 16:34:34', 'yyyymmdd HH24:MI:SS')

... which can then be inserted directly into an Oracle DATE column.

All a bit of a long way round, to be honest. Use SYSDATE in your INSERT statements instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.