Reputation: 61
I need to print the time of an operation taken by insert or update in a plsql block .So right now it gives the output as .23
secs I need to have output as 0.23
secs. If its greater than 0 then its coming fine.
Only to handle in case when its less than 1 sec and append 0 before decimal.
I am doing like this
(DBMS_UTILITY.get_time - l_start_time) / 100 secs
l_start_time is taken at the star of operation -
l_start_time := dbms_utility.get_time;
Upvotes: 0
Views: 44
Reputation: 36
While using to_char(l_duration, '999G990D00') it will work for any duration whether less than 0 or greater than 0 it's all depend on the format mask.
Upvotes: 1
Reputation: 142968
Apply TO_CHAR
function with desired format mask to the result. For example:
SQL> declare
2 l_start_time number := dbms_utility.get_time;
3 l_duration number;
4 l_cnt number;
5 begin
6 select count(*) into l_cnt from user_objects;
7 l_duration := (DBMS_UTILITY.get_time - l_start_time) / 100;
8 dbms_output.put_line(l_duration); --> short, unformatted
9 dbms_output.put_line(to_char(l_duration, '999G990D00')); --> short, formatted
10
11 --
12
13 select count(*) into l_cnt from all_objects;
14 l_duration := (DBMS_UTILITY.get_time - l_start_time) / 100;
15 dbms_output.put_line(l_duration); --> long, unformatted
16 dbms_output.put_line(to_char(l_duration, '999G990D00')); --> long, formatted
17 end;
18 /
,04 --> short, unformatted
0,04 --> short, formatted - that's what you'd want to see
5,89
5,89
PL/SQL procedure successfully completed.
SQL>
Upvotes: 2