Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

timestamp difference precision and dbms_output.put_line format.

zn553Jun 4 2021

Hello,
I calculate the difference between two date columns but the results are strange.
this is the script:

set serveroutput on
whenever sqlerror exit sql.sqlcode;
set echo off
SET VERIFY OFF
set heading off
SET FEEDBACK OFF
set serveroutput on size unlimited
set linesize 300
alter session set current_schema = my_schema;
-- alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
ALTER session SET TIME_ZONE='GMT';
Declare
vv_SchemaName VARCHAR2(15);
BEGIN
vv_SchemaName := Sys_Context('USERENV','CURRENT_SCHEMA');
FOR REVOKED IN (
select  a.transaction_id as trans_Id,
        e.eventcode,
        e.eventtime,
        a.time_received,
        (e.eventtime - a.time_received) * 86400 as total
  from      request_history_tbl a 
        join
            eventlog_tbl e
          on a.transaction_id = e.transaction_id
  where e.eventtime >= current_timestamp - 6/24
    and e.eventcode = '51'
    order by 3
    )
    LOOP
    dbms_output.put_line('revocation_request_seconds{' || 'transID=' || '"' || REVOKED.trans_Id || '"' || ',instance=' || '"' || vv_schemaname || '"' || '} ' || REVOKED.total );
    END LOOP;
END;
/

I would like by this to display some metrics for prometheus like this:
revocation_request_seconds{transID="xxxxx",instance="my_schema"} 0
I have two questions if I may:
is this the best way to add the quotes and curly brackets? and also the schema name?
the date calculation is not rounded up so i am getting this like:
revocation_request_seconds{transID="xxxxx",instance="my_schema"} .9999999999999999999999999999999999999996
how can i make the script display 1 instead of that large array of 9's ?

thank you

This post has been answered by Frank Kulash on Jun 4 2021
Jump to Answer

Comments

Post Details

Added on Jun 4 2021
3 comments
369 views