Monday, November 27, 2006

PL/SQL : Example using SysTimeStamp (milliseconds for SysDate)

Oracle's SYSDATE only goes to the second. If you want more precision, then you need to use the new SYSTIMESTAMP (available starting in Oracle 9). Source :


ltimestamp_start       timestamp;
ltimestamp_stop        timestamp;
linterval_diff         interval day to second;

ldt_temp               date;


ltimestamp_start := systimestamp;

  -- Routine to performance test... 
  for i in 1 .. 10000 loop
    select sysdate into ldt_temp from dual;
  end loop;

ltimestamp_stop := systimestamp;

linterval_diff := ltimestamp_stop - ltimestamp_start;

dbms_output.put_line('  Runtime Difference'||CHR(10)||LPAD('=',22,'='));
     '     Days : '||EXTRACT(DAY FROM linterval_diff)||CHR(10)||
     '    Hours : '||EXTRACT(HOUR FROM linterval_diff)||CHR(10)||
     '  Minutes : '||EXTRACT(MINUTE FROM linterval_diff)||CHR(10)||
     '  Seconds : '||EXTRACT(SECOND FROM linterval_diff) );
Results :
27-NOV-06 PM
27-NOV-06 PM

Runtime Difference
Days : 0
Hours : 0
Minutes : 0
Seconds : 1.006717


S├ębastien Lesaint said...

Thanks for this post, helped me benchmark pl/sql methods of mine that always took less than one seconds (but are used in reality quite intensively).


Anonymous said...

Thank you very much, this helped me a lot.

God bless and keep up the good work

Anonymous said...

Thank you! That's exactly what I was looking for!

Anonymous said...

Great, thanks a lot!

Anonymous said...

Thank you!! u da man!! Just awesome!! It helped me so much!

Vova said...

Thank you very much!
Indeed what I was looking for.

Yose Abramovic said...

Aw, this was a really nice post. In concept I would like to put in writing like this moreover – taking time and precise effort to make an excellent article… but what can I say… I procrastinate alot and under no circumstances appear to get one thing done. online casino games