Improve Oracle Performance by Reducing Calls to SYSDATE

By Richard Niemiec on April 21, 2013


The SYSDATE variable is a convenient method of retrieving the current date and time. Calls to SYSDATE involve some overhead; therefore, if this variable is needed to log the date of certain processing, the call to this variable should be made once at the start of the program rather than at each iteration. This technique of calling SYSDATE once at the start of the program assumes the date logging is desired at the point in time the program started. The reduction of SYSDATE calls is illustrated in the following example. The example loops through 10,000 iterations, calling SYSDATE (only the date portion of the variable because the TRUNC function is used to truncate the time portion) every iteration.

 

0606_001

 

The following output shows the timing of two executions of the preceding code segment:

 

0606_002

 

The following PL/SQL code segment has been modified to retrieve the SYSDATE only once, at the beginning of the program, and set to another variable each iteration.

 

0606_003

 

The following output shows the timing of two executions of the preceding code segment:

 

0606_004

 

As evident in the preceding example, overhead is associated with the SYSDATE call, and the number of calls to SYSDATE should be reduced, if possible.

TIP

Attempt to limit the calls to SYSDATE in iterative or recursive loops because overhead is associated with this variable. Set a PL/SQL DATE variable to SYSDATE in the declaration and reference the PL/SQL variable to eliminate the overhead.

Related Posts

Leave a Reply