Timestamp with milli/micro/nano seconds

As part of performance and run time of a query or a function we might need to capture time in milli/micro/ nano seconds. Below snippets would help in such scenarios:

By default localtimestamp will give upto 6 decimal places of a sec.
to get nano sec upto 9 decimal use localtimestamp(9)

declare
l_starttime timestamp(9);
l_endtime timestamp(9);
l_count number:=0;
l_Diff number:=0;

begin
select localtimestamp(9) into l_starttime from dual;
 dbms_output.put_line('Start Time: ' || l_starttime);
 
select count(*) into l_count
from PO_line_locations_all pll, po_headers_all PHA
where pll.po_header_id = pha.po_header_id
and exists (select 1 from po_requisition_lines_all prl,po_requisition_headers_all prh 
             where prl.requisition_header_id = prh.requisition_header_id 
               and prl.blanket_po_header_id = pha.po_header_id)
and pll.po_header_id = <enter header id>;

select localtimestamp(9) into l_endtime from dual;
 dbms_output.put_line('End Time: ' || l_endtime);
 l_Diff := extract(SECOND FROM(l_endtime - l_starttime));
 dbms_output.put_line('DiffTime: ' || l_Diff ||' - '||l_count);
end;

  







Comments

Popular posts from this blog

PO & Receipt Query

Supplier SQL query

Inventory Item Attributes, Categories, Vendor & Costs