Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
    
Are you maybe looking for current_timestamp? INSERT INTO ... VALUES (current_timestamp, ...); –  a_horse_with_no_name Apr 28 at 14:16
    
@a_horse_with_no_name Thank you, but I need to generate it in Perl. –  Peter Horvath Apr 28 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 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 at 15:34

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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