Job to retrieve difference in seconds (sometimes days)

Hi, good day everyone.
I managed (with your help btw) to get the difference (in seconds for each time an UTR 'NAME' fails and return) with a job which runs every time at morning for the last day (sysdate -1), the problem is that I need to retrieve the data when the time is null (when the UTR didn't return that day), here's an example:
CREATE TABLE     evtmsg
(       evt_date             DATE,
     message          VARCHAR2 (50)
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('04/10/2010 8:39:05', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02MCD-1 fail');*
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('04/10/2010 8:39:05', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02MAD-1 fail');*
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('04/10/2010 8:39:08', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02MCD-1 return');*
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('04/10/2010 8:39:50', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02ZPD-1 fail');*
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('04/10/2010 8:39:50', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02MAD-1 return');*
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('05/10/2010 5:40:22', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02MCD-1 fail');
INSERT INTO evtmsg (evt_date, message) VALUES (TO_DATE ('05/10/2010 8:38:50', 'DD/MM/YYYY HH24:MI:SS'), 'UTR 02ZPD-1 return');In this case, if today was 5th (after running the job in the morning (01:00:00 a.m)), I'd have the next outcome:
Select * from qtyuna;
04/10/2010 8:39:05     04/10/2010 8:39:08   UTR 02MCD-1    3
04/10/2010 8:39:05     04/10/2010 8:39:50   UTR 02MAD-1    45
04/10/2010 8:39:50     null                           UTR 02ZPD-1    nullAnd if I do the same query on 6th (after the job) I'd like to get this:
Select * from qtyuna;
04/10/2010 8:39:05     04/10/2010 8:39:08   UTR 02MCD-1    3
04/10/2010 8:39:05     04/10/2010 8:39:50   UTR 02MAD-1    45
04/10/2010 8:39:50     05/10/2010 8:39:55   UTR 02ZPD-1     86405
05/10/2010 5:40:22     null                           UTR 02MCD-1    nullThe job I have is this
INSERT INTO qtyuna (datefa, datere, rtunam, timefa)
                SELECT evt_date_fallo, evt_date_retorno, id, TO_CHAR(TO_CHAR(evt_date_retorno, 'SSSSS') - TO_CHAR(evt_date_fallo, 'SSSSS'))seconds,
                FROM    (SELECT evt_date evt_date_fallo,
                LEAD(evt_date) OVER (partition by id ORDER BY id||TO_CHAR(evt_date, 'yyyymmddhh24miss')||CASE status WHEN 'return' THEN 1 ELSE 2 END) evt_date_retorno,
                id,
                status
                  FROM  (SELECT evt_date,
                      SUBSTR(message, 1, 11) id,
                      SUBSTR(message, 13) status
                      FROM   [email protected]
                      WHERE  message LIKE 'UTR%'
                      AND    categ = 1
                      AND    TRUNC(evt_date) = TRUNC(SYSDATE - 1)))
                  WHERE    status like '%fail%'
                  ORDER BY evt_date_fallo;I don't know if I need another job to do that... if so, could you tell me how?
Regards

Hi,
It looks like the main problem is how you are computing the seconds column.
In Oracle, if you subtract one date from another, you get the difference in units of 1 day. If you want the difference in seconds, multiply the difference in days by the number of seconds in one day. There's no need to use TO_CHAR, and nothing special has to be done if the DATEs are on different calendar days.
In your case, once you have the two DATEs identified, the way to get the number of seconds between them is:
(evt_date_retorno - evt_date_fallo) * 24 * 60 * 60because each day has 24 hours, each hour has 60 minutes, and each minute has 60 seconds.
There are lots of other things you could change. In particular, the way you are using LEAD is very confusing. If you are using Oracle 10 or higher, then I suggest using FIRST_VALUE instead, like this:
DEFINE     TEST_SYSDATE     = "(DATE '2010-10-05' + (1 / 24))"
-- INSERT INTO qtyuna (datefa, datere, rtunam, timefa)     -- Removed for testing
WITH    got_evt_date_retorno     AS
     SELECT  evt_date               AS evt_date_fallo
     ,     LAST_VALUE ( CASE
                            WHEN  SUBSTR (message, 13) = 'return'
                       THEN  evt_date
                    END
                      IGNORE NULLS
                  ) OVER ( PARTITION BY  SUBSTR (message, 1, 11)
                               ORDER BY       evt_date          DESC
                      )             AS evt_date_retorno
     ,       SUBSTR (message, 1, 11)            AS id
     ,     SUBSTR (message, 13)            AS status
     FROM     evtmsg
     WHERE     SUBSTR (message, 1, 3)     = 'UTR'               -- More efficient than LIKE
--     AND     categ                     = 1               -- There's no categ in the sample data
     AND     evt_date          < TRUNC (&test_sysdate)     -- Use SYSDATE in Production
SELECT       evt_date_fallo
,       evt_date_retorno
,       id
,       (evt_date_retorno - evt_date_fallo) * 24 * 60 * 60     AS seconds
FROM       got_evt_date_retorno
WHERE       SUBSTR (status, -4)     = 'fail'               -- Do we need SUBSTR here?
-- ORDER BY  evt_date_fallo                         -- For testing only
;You wrote this with a separate sub-query to get id and status from message. That's not a bad idea; you could add another sub-query above.
I changed SYSDATE to a substritution variable for testing. After you're through with testing, change &test_stsdate to SYSDATE.

Similar Messages

  • (edu.mit.kerberos.krb5kdc) Job chrashed.  Every 10 seconds for days now.

    My console is showing that com.apple.launchd[1] (edu.mit.Kerberos.krb5kdc) Job appears to have crashed: Segmentation fault. Throttling respawn: will start in 10 seconds.
    Then it saves a crash log.
    Does anyone know how to fix this? I am not sure when it started but it has been going non-stop for days. Every 10 seconds - Crash and log.
    I called apple support and they had me reboot into safe mode. Not sure why, but it didn't help.
    Please help if you can.
    Ken Loggains
    Here is a bit from the log:
    Process: krb5kdc [1075]
    Path: /usr/sbin/krb5kdc
    Identifier: krb5kdc
    Version: ??? (???)
    Code Type: X86-64 (Native)
    Parent Process: launchd [1]
    Date/Time: 2010-03-12 16:22:49.428 -0600
    OS Version: Mac OS X 10.6.2 (10C2234)
    Report Version: 6
    Exception Type: EXCBADACCESS (SIGSEGV)
    Exception Codes: KERNINVALIDADDRESS at 0x0000000100053166
    Crashed Thread: 0

    I just had this same problem on my server. The only difference is it is an Xserve insted of a Mac Mini.
    I restarted the whole operating systems and that appeard to have fixed the problem but I do not know what I cause was.
    Did you figure anything out?

  • Time to difference in seconds

    Hi, im implementing a reminder function whereby
    a user can input a time in format HH:MM:SS and
    the program will prompt them with a reminder at
    that time.
    I have already used the Calender.getInstance()
    method to obtain the current HH:MM:SS and i need
    to find the difference (in seconds) between
    the user input time and the current time.
    It needs to be in seconds as this is what will
    be passed into the TimerTask/Timer part of my code.
    Though it would appear to be an easy job, bear in
    mind that if the user entered 20:30:00 and the
    current time was 20:29:50 then the result would
    be almost 24hrs worth of seconds!
    So far i haven't found a standard feature that
    can accomplish this and the only alternative
    seems to be a mess of if statements so any
    help would be appreciated ;)
    thanks,
    cam

    I dont think any of you understood the problem
    i face, maybe original question wasnt clear
    enough...I understood just fine, you aren't listening to our suggestions!!
    for example, using the getTimeInMillis() method
    you all suggest, if the input was
    11:30:59 and current time was 11:30:00
    then the difference returned is 59
    However, if the input was 03:30:00 and current time was 11:30:00
    then the difference returned is (approx) -29000then make it work by saying if the time is before the current time for the day, just add a day to the calander so that it would be the next day, thus when you got the getTimeInMillis() for that time it would now be the next day at 11:30:00 not today which would give you how many ever seconds that would be!! It is that easy :) I was even nice enought to write some code for you. here is the output that I got from it
    now date is Wed Dec 04 08:53:37 CST 2002
    later date is Wed Dec 04 11:11:00 CST 2002
    yesterday date is Tue Dec 03 11:11:00 CST 2002
    now is 1039013617546
    later is 1039021860000
    later - now is 8242454
    yesterday is 1038935460000
    yesterday - now should be negative now -78157546
    Adding one to yesterday to make it today
    yesterday is now 1039021860000
    yesterday - now should be positive now 8242454
    Good Luck,
    Pup
    * DateTemp.java
    * Created on December 4, 2002, 8:28 AM
    * @author  Lyle Eckert
    public class DateTemp {
        /** Creates a new instance of DateTemp */
        public DateTemp() {
        public static void main(String[] Args) {
            java.util.GregorianCalendar now = new java.util.GregorianCalendar();
            java.util.GregorianCalendar later = new java.util.GregorianCalendar(2002,11,04,11,11,00);
            java.util.GregorianCalendar yesterday = new java.util.GregorianCalendar(2002,11,03,11,11,00);
            System.out.println("now date is " + now.getTime().toString());
            System.out.println("later date is " + later.getTime().toString());
            System.out.println("yesterday date is " + yesterday.getTime().toString());
            System.out.println("now is " + now.getTimeInMillis());
            System.out.println("later is " + later.getTimeInMillis());
            System.out.println("later - now is " + (later.getTimeInMillis() - now.getTimeInMillis()));
            System.out.println("yesterday is " + yesterday.getTimeInMillis());
            System.out.println("yesterday - now should be negative now " + (yesterday.getTimeInMillis() - now.getTimeInMillis()));
            while(yesterday.before(now)) {
                System.out.println("Adding one to yesterday to make it today");
                yesterday.add(later.DATE, 1);
            System.out.println("yesterday is now " + yesterday.getTimeInMillis());
            System.out.println("yesterday - now should be positive now " + (yesterday.getTimeInMillis() - now.getTimeInMillis()));

  • How to: Schedule a job to run on the first business day of the month

    In Oracle 10.2.0.3, is there a way to schedule a repeating job to run on the first business day of the month? For example, if the first of the month falls on a weekend (such as Saturday, 11/01/2008), I would like the job to run automatically on Monday (for example, 11/03/2008) instead.

    set serveroutput on
    begin
      print_dates('FREQ=MONTHLY;BYDAY=MON,TUE,WED,THU,FRI;BYSETPOS=1;',
          to_timestamp_tz('01-JAN-2008 12:00:00','DD-MON-YYYY HH24:MI:SS'), 12);
    end;
    Gives:
    TUE 01-JAN-2008 (001-01) 12:00:00 -07:00 -07:00
    FRI 01-FEB-2008 (032-05) 12:00:00 -07:00 -07:00
    MON 03-MAR-2008 (063-10) 12:00:00 -07:00 -07:00
    TUE 01-APR-2008 (092-14) 12:00:00 -07:00 -07:00
    THU 01-MAY-2008 (122-18) 12:00:00 -07:00 -07:00
    MON 02-JUN-2008 (154-23) 12:00:00 -07:00 -07:00
    TUE 01-JUL-2008 (183-27) 12:00:00 -07:00 -07:00
    FRI 01-AUG-2008 (214-31) 12:00:00 -07:00 -07:00
    MON 01-SEP-2008 (245-36) 12:00:00 -07:00 -07:00
    WED 01-OCT-2008 (275-40) 12:00:00 -07:00 -07:00
    MON 03-NOV-2008 (308-45) 12:00:00 -07:00 -07:00
    MON 01-DEC-2008 (336-49) 12:00:00 -07:00 -07:00
    and the print_dates function is (10.2):
    create or replace procedure print_dates
      cal_string in varchar2,
      start_date in timestamp with time zone,
      nr_of_dates in pls_integer
    is
      date_after timestamp with time zone := start_date - interval '1' second;
      next_execution_date timestamp with time zone;
    begin
      dbms_output.put_line('  -->');
      for i in 1 .. nr_of_dates
      loop
        dbms_scheduler.evaluate_calendar_string
         (cal_string, start_date, date_after, next_execution_date);
        dbms_output.put_line(to_char(next_execution_date,
                        'DY DD-MON-YYYY (DDD-IW) HH24:MI:SS TZD TZH TZR'));
        date_after := next_execution_date;
      end loop;
    end;
    [\pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 3 Messages getting struck in SMQ2 at same time with difference in seconds

    Hi all,
    Three  EOIO messages with Queue name QBTJ.......................(same Queue id  for 3days)
    that is day1 QBTJ(message (a)  queue id=day2 QBTJ  queue id=day3 QBTJ  queue id
    day1 QBTJ(message (b)  queue id=day2 QBTJ  queue id=day3 QBTJ  queue id
    day1 QBTJ(message (c)  queue id=day2 QBTJ  queue id=day3 QBTJ  queue id
    .These are getting struck in smq2 at same times (compared the timings 3 days).the time at which these messages are getting struck are same with the difference in seconds.
    Other than these 3 different times ,these messages are moving with out strucking in SMQ2.
    I have two questions here
    1)what could be the reason for only these three messages are getting struck in smq2
    2)is there any parameter which could be set in SXMB_ABMIN to unlock the queue automatically with out going to smq2 and manually unlocking.
    Please do not send nonrelavent blogs
    Thanks,
    Srinivasa

    Hello,
    you can schedule the report RSQIWKEX in your XI system. This report does automatically unlock all queues.
    See the blog for more details.
    regards,
    Björn

  • Oracle Job in progress for too long (3 days)

    Hi guys,
    i am using oracle 10.2.0.3 database. One of the oracle job is in progress for almost 3 days & in active state.
    i tried enabling trace but didnt get anything. please let me know what should i do. EM also dont show any current or previous SQL & the wait event is "jobq slave wait" ....
    please help.....

    Here is the current situation i can see at OEM.
    Current Status ACTIVE
    Serial Number 4285
    DB User Name JOBS
    OS Process ID 6492
    Logged On Since May 29, 2009 1:12:33 PM
    Logged On For 3 Days, 22 Hours, 49 Minutes, 3 Seconds
    Connection Type DEDICATED
    Type USER
    Resource Consumer Group Unavailable
    Client
    OS User Name admin
    OS Process ID 6492
    Host ORACLE_PRODUCTION
    Terminal ORACLE_PRODUCTION
    Current Client ID Unavailable
    Current Client Info Unavailable
    Application
    Current SQL None
    Current SQL Command UNKNOWN
    Previous SQL None
    Last Call Elapsed Time 3 Days, 22 Hours, 49 Minutes, 2 Seconds
    SQL Trace DISABLED
    Open Cursors 7
    Program ORACLE.EXE (J000)
    Service SYS$USERS
    Current Module Unavailable
    Current Action Unavailable
    Contention
    Blocking Session ID None
    Wait
    Current Wait Event jobq slave wait
    Current Wait Class Idle
    Waiting for 2 Minutes, 11 Seconds
    P1 None
    P2 None
    P3 None
    Object None

  • How do you find the difference in no. of days between 2 dates?

    How do you find the difference in no. of days between 2 dates ?

    There are 2 way to solve this: using java.util.GregorianCalendar or java.util.Date (like jesper1 suggested), depending what kind of solution You need:
            GregorianCalendar gc1 = new GregorianCalendar(2001, 01, 01, 23, 00, 00);
            GregorianCalendar gc2 = new GregorianCalendar(2001, 01, 03, 10, 00, 00);
            // 1st way using GregorianCalendar
            int diff1 = gc1.get(GregorianCalendar.DATE) - gc2.get(GregorianCalendar.DATE);
            System.out.println("Differnce: " + diff1);
            // 2nd way using Date
            int diff2 = (int)(gc1.getTime().getTime() - gc2.getTime().getTime()) / (24 * 60 * 60 * 1000);
            System.out.println("Differnce: " + diff2);Note: There are 2 days between the given dates, but exactly 1 day and 11 hours.
    The first solution returns "-2", the second returns "-1".
    (... and a 4th posting also won't help ...)

  • Finding the difference in no. of days between 2 dates

    Finding the difference in no. of days between 2 dates

    http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A54&qt=days+difference&x=12&y=11

  • HT201317 Is it possible to retrieve photos once the 30 days is up or once the photo stream exceeds the 1000 photo limit?

    Is it possible to retrieve photos once the 30 days is up or once the photo stream exceeds the 1000 photo limit?

    No.  Photo stream photos are not backed up so there is no way to restore them.  Only camera roll photos are backed up.

  • Date difference in years,month,days should consider Leap Year

    I would like to know how to compute the difference between two Date, and get the difference in years,months,days, PS. Should include New Year
    Eg Date1 : 01/01/2000
    Date2: 01/01/2005
    Diff: years=5, months=0 days=1 for a leap year is included'2004'

    I would like to know how to compute the difference
    between two Date, and get the difference in
    years,months,days, PS. Should include New Year
    Eg Date1 : 01/01/2000
    Date2: 01/01/2005
    Diff: years=5, months=0 days=1 for a leap year is
    included'2004'If any program I was using gave me that result, I would consider it a bug.

  • SQL Query Help/ Converts seconds to day:hr:mi:se

    I have query that returns value in seconds. How i will convert those seconds in DAY:HOUR:MIN:SEC in the same query? What will be the mathematical formulae or alogorithim for this?
    Thanks
    Munis Warsi
    null

    Seriously, you post 750+ lines of unformatted SQL statement and a completely unreadable and unformatted explain plan and you expect people to be able to help with that?
    From what I can see it looks like some sort of query against an Oracle APPS database, and there are numerous calls to PL/SQL functions in there, so you're creating a multitude of context switches between the SQL and PL engines... that's known to cause performance problems.
    Take a read of the discussions linked in the FAQ: Re: 3. How to  improve the performance of my query? / My query is running slow.
    And also consider if your question would be better asked in the Oracle Apps forum space instead.

  • Just updated from elements 11 to 13. When I try to use Levels in Elements 13. I click on the slider with my bamboo pen and nothing happens for a few seconds, sometimes not at all. This worked fine in Elements 11.

    Just updated from elements 11 to 13. When I try to use Levels in Elements 13. I click on the slider with my bamboo pen and nothing happens for a few seconds, sometimes not at all. This worked fine in Elements 11.

    Never mind my question on the photoshop elements 13 trying to install the camera raw update. It has been taken care of thank goodness!

  • Final Cut X crashed while moving project, how can I retrieve media that has vanished. Relinking doesn't do the job. This is the second it happens. The program seems to hang as soon as I select "move project".

    My system crashes several times a day. This is getting exhausting and very expensive.

    Have you tried deleting your preferences?
    http://www.digitalrebellion.com/prefman/
    Tony

  • My MacBook Pro keeps freezing for a few seconds (sometimes with the beach ball)... HELP

    My computer would not boot up past the grey screen a few days ago so I brought it into the Genius Bar and they fixed it. It finally turns on but I find it's constatly freezing for about 2-10 seconds every once in a while. Whether it's in Safari, Outlook, iTunes, VLC, etc. everything stops and sometimes I get the beachball. I tried disk repair and permissions repair, so I'm not sure what to do next!

    try doing a SMC RESET if you've tried repair permissions...

  • Why does my ipod touch stop playing songs when i click to play, it plays for a few seconds sometimes longer and then goes onto the next song. Help!

    Please help,my ipod touch stops playing songs sometimes a few seconds in and then other times halfway. It cant be the song because different songs do it each time. Ive tried to restore it and it makes no difference :(
    Please help as this problem gets very annoying. Thanks!

    Did you restore to factory defaults/new iPod and sync stuff to your iPod?  If you restore from backup there may be some corruption that is now in the backup.

Maybe you are looking for

  • Display Issues in Premiere Pro CS4

    I'm having some weird display glitches in Adobe Premiere Pro CS4 in the timeline area. I attached a picture that shows what it looks like. This happens whenever I drag clips on the timeline and it makes it so it takes a lot longer to edit my videos.

  • Can I Turn a Video 90º?

    I shot a video holding my iTouch 4th gen vertically. When I e-mailed it, it appears 90º (sideways). The video is fairly important, so I'd like to know if there's any way to rotate it back such that it views normally when e-mailed. Photos are easy to

  • Active Directory accountExpires=Error:87

    Hi, does anyone know what this error code means for the attribute accountExpires of a user account in AD?

  • IPhone 6 locked in portrait view. How to unlock?

    iPhone 6 locked in portrait view. How to unlock to allow landscape view?

  • Workaround--How I put old photo stream on new device

    So I bought a new iPhone and turned on PhotoStream and was pretty upset that only the last 30 days worth of photo stream photos made it back to my device...  I did a lot of reading and found out that nothing was set-up wrong, it was just the way phot