1

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 ocaltime scalar 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 unix gettimeofday() 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.

0

1 Answer 1

3

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 and acknowledge you have read our privacy policy.

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