Difference between dates

11.2.0.4

not just a simple less question.

Having a job of populating a table, table has several fields, 1 field is a date stamp

create table t1

(date of col1,

lotsofcols varchar2 (100))

Work is essentially a

Insert into t1 (sysdate, 'somedata');

Work can run hundreds of times per minute, I need to know when something happens when labour has not filled the table within a certain time, the time is different during the day, but if I get it working for a minute away its fine.  I only need to run hourly check.   So I want to select in the table all records during the preceding hour, then select the next inserted row, fewer dates and check whether it was more than a minute.   I can tell you that in a few ways, but the main SQL is what Im in trouble with.    I don't have a sequence number of the table.

drop table t1;

create table t1

(date of col1,

col2 varchar2 (10));

-run 4 times this

Insert into t1

values (sysdate, 'abc');

-run once to get a tape with a gap of 10 minutes

Insert into t1

values (sysdate + (10 / 24 / 60), 'abc')

commit;

-all records in the last hour

Select *.

from t1

where col1 > (sysdate - (24 / 60))

COL1 COL2

------------------- ----------

30/01/2015-10:46:07 abc

30/01/2015-10:46:08 abc

30/01/2015-10:46:10 abc

30/01/2015-10:46:12 abc

30/01/2015-10:56:16 abc

I want to select col1 4th row rank 5 col1, rank 3 rank col1 col1 4 etc, if the gap is greater than 60 seconds, then return - something, maybe an additional column of an instruction box

Select *.

from (select col1

col2

lag (col1) on prev_col1 (order by col1)

, numtodsinterval (col1 - gal (col1) (col1 order), 'DAY') diff

from t1

)

where diff > numtodsinterval (1, 'MINUTE')

Tags: Database

Similar Questions

  • code succcessive to genereate difference between dates in a table

    First create and insert statements;
    create table schedule(iloan_code number , schedule_date date);
    
    insert into schedule values(1001, to_date('01-jun-2012'));
    insert into schedule values(1001, to_date('01-jul-2012'));
    insert into schedule values(1001, to_date('01-aug-2012'));
    insert into schedule values(1001, to_date('01-sep-2012'));
    insert into schedule values(1001, to_date('01-oct-2012'));
    commit;
    The output of the table of the ANNEX should be now like this:
    ILOAN_CODE     SCHEDULE_DATE
    1001              01-JUN-12
    1001              01-JUL-12
    1001              01-AUG-12
    1001              01-SEP-12
    1001              01-OCT-12
    We want an additional column by name as well as the existing columns DAYS that would be the difference between dates.

    First line should be the difference between sysdate as well as the date of June 1, 2012 and successive lines must be the difference between successive calendar date

    For example in the second row the DAYS column should represent the difference between 1 July 2012 and 1 June 2012 and so on for the following ranks too.

    We need get the result by a SELECT statement

    The output of the table in the ANNEX must be something like that.
    iloan_code      schedule_date     days     Logic which we need 
    1001     1-Jun-12     22     sysdate-1st June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 1st June 2012
    1001     1-Aug-12     31     difference between 1st aug 2012  and 1st July 2012
    1001     1-Sep-12     31     difference between 1st sep  2012 and 1st aug  2012
    1001     1-Oct-12     30     difference between 1st oct 2012 and 1st sep 2012
    Please notify;

    Hello

    You can change the Hoek solution like this:

    SELECT    iloan_code
    ,             schedule_date
    ,             schedule_date - LAG ( schedule_date
                                , 1
                         , TRUNC (SYSDATE)
                         ) OVER (ORDER BY schedule_date)     AS days_between
    FROM      schedule
    ORDER BY  schedule_date
    ;
    

    If all schedule_dates will be after SYSDATE, then you need not the CASE expression to test if it is.
    The argument optional 3rd to LAG is a return value in case there is no previous line.

    Sri says:
    ... The output of the table in the ANNEX must be something like that.

    iloan_code      schedule_date     days     Logic which we need
    1001     30-Jun-12     07     sysdate-30June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 30 June 2012 ...
    

    The difference between 30 June 2012 and July 1, 2012 is not only 1 day?

  • Second difference between dates GMT?

    Hello

    I need to get the second difference between a date later GMT and current date of GMT.

    My code looks like this:

    Calendar futureDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));futureDate.set(Calendar.YEAR, 2009);futureDate.set(Calendar.MONTH, 11);futureDate.set(Calendar.DATE, 12)futureDate.set(Calendar.HOUR, 10)futureDate.set(Calendar.MINUTE, 43)futureDate.set(Calendar.SECOND, 18);
    
    int secs = (futureDate.getTime().getTime() - System.currentTimeMillis()) / 1000;
    

    This code gives me 12 hours too many seconds. I'm I have GMT + 7 time zone. DateTime, the value source Blackberry.

    When I debug, and print the futureDate, it shows me my timezone instead of GMT.

    Another weird thing. If I subtract the TimeZone.getDefault () .getRawOffset () in my calculation of seconds, the seconds are then 7 hours in advance. Where are these 5 hours from extra?

    Thank you.

    Sorry, just a little chip, I don't have the time to carefully review your problem (maybe do later) but two things:

    (1) System.currentTimeMillis () returns the time UTC.  I think that CMJ is incorrect when he says that it returns local time.

    (2) GMT is NOT necessarily UTC time on the device.  GMT in London at the present time is UTC to 1, because we (I'm in the United Kingdom) use Daylight Saving.  If you want to discover the real hour GMT, on the device or the Simulator, set time GMT from Casablanca.

    I need to check these, do not have the time, but here are some other thoughts on the top of my head.

    (a) timezone "GMT" is, in fact, Casablanca GMT, i.e. not affected by Daylight Saving.

    (b) Note When you specify the time of the calendar, there are two forms of time:
    TIME - what you used, can be morning or afternoon

    HOUR_OF_DAY - which I think is what you should use.

    So change your code to use HOUR_OF_DAY, and I suspect that this could work.  But as noted, just off the top of my head...

  • Difference between Date of invoice and Date GL accounting Date Oracle AP

    Hello

    I have a question that might help a lot of people too late.
    I tried to run these queries
    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia. INVOICE_DATE <>aida. ACCOUNTING_DATE

    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia.GL_DATE <>aida. ACCOUNTING_DATE

    I see that there are a lot of results for these queries, where the Date of the invoice is not equal to the posting date and of the GL_Date of an invoice does not match the posting date in the distribution table.
    So, what is the difference between these dates.
    And if I had to take the date of posting of the invoice of the document, the date on which I have to take for these invoices in AP

    Thank you
    Bob

    Hello

    Date of GL:

    The date used to determine the right time of accounting for the transactions of your invoice and payment of GL. You assign a GL Date on your invoice during invoice entry
    and your payments during the creation of payment.

    Date of invoice:

    The invoice date that you assign to an invoice, you enter in Payables. Accounts payable uses this date to calculate the invoice due date, the terms of payment of the invoice. The invoice date may be the date of the invoice, or it can be another date that you specify.

    Posting date:

    The GL Date for distributions of the invoice. If you do not enter a value here or enter a value for GL Date when you submit Payables Open Interface Import, accounts payable will allocate a GL Date based on the GL Date set in the region of the invoice of the Payables Options window.

    Kind regards
    Rahul

  • Difference between Date hh: mm

    Hello

    I'm having the following table, I want the difference between time in hh & another exit as hh: mm with rounded seconds.


    CREATE TABLE 'ITIP. "" TOTO ".
    ("N1" VARCHAR2 (100),)
    "T1D" THAT DAY.
    'T2D' DAY
    )


    Insert into FOO (n1, t1d and T2D)
    values ('TT', to_date (25 June 2012 10:46:56 ',' dd-mm-yyyy hh24:mi:ss'), to_date (25 June 2012 10:51:53 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('TT', to_date (25 June 2012 10:51:53 ',' dd-mm-yyyy hh24:mi:ss'), to_date (25 June 2012 10:51:57 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('TT', to_date (25 June 2012 10:32:06 ',' dd-mm-yyyy hh24:mi:ss'), to_date (25 June 2012 10:43:09 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('TT', to_date (25 June 2012 10:43:09 ',' dd-mm-yyyy hh24:mi:ss'), to_date (25 June 2012 10:53:09 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('UU', to_date (25 June 2012 10:46:56 ',' dd-mm-yyyy hh24:mi:ss'), to_date (June 25, 2012 21:44:39 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('UU', to_date (27 June 2012 10:51:53 ',' dd-mm-yyyy hh24:mi:ss'), to_date (June 27, 2012 11:46:10 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('UU', to_date (28 June 2012 10:32:06 ',' dd-mm-yyyy hh24:mi:ss'), to_date (28 June 2012 18:45:32 ',' dd-mm-yyyy hh24:mi:ss'));))
    Insert into FOO (n1, t1d and T2D)
    values ('UU', to_date (June 29, 2012 14:22:13 ',' dd-mm-yyyy hh24:mi:ss'), to_date (June 29, 2012 17:24:20 ',' dd-mm-yyyy hh24:mi:ss'));))
    commit;


    What is the result when we substract two dates?, as I want the difference between time in hh & another exit as hh: mm with rounded seconds.

    Please suggest a query for the same thing.

    Thank you

    Hello

    user12009546 wrote:
    ... What is the result when we substract two dates?

    This is the number of days between these two dates. You can convert than an INTERVAL, which is more like what you want, using NUMTODSINTERVAL:

    NUMTODSINTERVAL ( dt2 - dt1
                    , 'DAY'
                    )
    

    If you don't want that all the information, you can use SUBSTR or regular expressions to get only the part you want.

    I would also like the difference between the time in hh & another exit as hh: mm with rounded seconds.

    Please suggest a query for the same thing.

    If the difference will always be between 0 and 24 hours, then you can do something like diff_c below:

    SELECT       dt1
    ,       dt2
    ,       NUMTODSINTERVAL ( dt2 - dt1
                       , 'DAY'
                     )          AS diff_i
    ,       TO_CHAR ( ROUND ( TRUNC (SYSDATE) + (dt2 - dt1)
                           , 'MI'
                     )
                , 'HH24:MI'
                )               AS diff_c
    FROM      toto
    ;
    

    Output:

    DT1                 DT2                 DIFF_I                         DIFF_
    ------------------- ------------------- ------------------------------ -----
    25-06-2012 10:46:56 25-06-2012 10:51:53 +000000000 00:04:57.000000000  00:05
    25-06-2012 10:51:53 25-06-2012 10:51:57 +000000000 00:00:04.000000000  00:00
    25-06-2012 10:32:06 25-06-2012 10:43:09 +000000000 00:11:03.000000000  00:11
    25-06-2012 10:43:09 25-06-2012 10:53:09 +000000000 00:10:00.000000000  00:10
    25-06-2012 10:46:56 25-06-2012 21:44:39 +000000000 10:57:42.999999999  10:58
    27-06-2012 10:51:53 27-06-2012 11:46:10 +000000000 00:54:17.000000000  00:54
    28-06-2012 10:32:06 28-06-2012 18:45:32 +000000000 08:13:26.000000000  08:13
    29-06-2012 14:22:13 29-06-2012 17:24:20 +000000000 03:02:07.000000000  03:02
    
  • time difference between dates

    I managed to present the session for the start date variable: CAST (VALUEOF (s_sd) AS DATE)
    and for the end date: CAST (VALUEOF (s_ed) AS DATE)

    How can I show the number of days of interval between them?

    Create an another session variable to calculate the difference between the dates.

    Select DATEDIFF (DD, "MM DD YYYY","MM DD YYYY") FROM DUAL;

    Hope that the question is answered.

    Update of the Post:

    The function datediff above would only work in SQL Server, if you use the oracle database, use the code below:

    SELECT SYSDATE - TO_DATE('20081205','YYYYMMDD') datediff FROM DUAL;

    Note: You can replace the sysdate with your custom date, but do not forget to mention the data format of date after the mention of the date of your custom.

    Thank you
    -Laurence.

  • To return the rows when there is a certain difference between dates

    Hello.

    I have a table called

    #president #.
    pres_name
    BIRTH_DATE

    and

    #winner #.
    name
    year_elected

    I wish I had all the presidents returned, who where under the age of 50 years when they elected.
    year_elected is only a 4-digit number; 1924 etc. While birth_date is 2001-01-01 etc.

    I have no idea how to make this work, ive tried substr and one things and a lot of other weird (prob wrong).
    select distinct p.pres_name, substr(p.birth_date, 0, 4), w.year_elected
    from president p, winner w
    where p.pres_name = w.name
    I did this witch query will show me all the presidents and their dates for the election and the date of birth. Now I just want something that returns only the guys where there is a difference in value 49 (?) between birth_date and year_elected


    Johan

    Edited by: user10248089 02-Oct-2008 00:42

    Based on information from Dave on presidents being elected the first Tuesday of November...

    SQL> with president as (select 'Bob' as pres_name, to_date('1/7/1934','DD/MM/YYYY') as birth_date from dual union all
      2                     select 'Fred', to_date('13/5/1950','DD/MM/YYYY') from dual union all
      3                     select 'Jim', to_date('21/12/1960','DD/MM/YYYY') from dual)
      4      ,winner    as (select 'Bob' as name, '1979' as year_elected from dual union all
      5                     select 'Fred', '2005' from dual union all
      6                     select 'Jim', '2000' from dual)
      7  --
      8  select p.pres_name, p.birth_date, w.year_elected
      9        ,trunc(months_between(next_day(to_date('01/11/'||w.year_elected,'DD/MM/YYYY'),'TUE'),birth_date)/12) as age
     10  from president p join winner w on (p.pres_name = w.name)
     11  /
    
    PRES BIRTH_DAT YEAR        AGE
    ---- --------- ---- ----------
    Bob  01-JUL-34 1979         45
    Fred 13-MAY-50 2005         55
    Jim  21-DEC-60 2000         39
    
    SQL>
    

    And the WHERE clause can be applied based on the same calculation as described in the age column

  • Differences between Data Pump and always by inheritance, import and export

    Hi all

    I work as a junior in my organization dba and I saw that my organization still uses legacy import and export utility instead of Oracle Data Pump.

    I want to convence my manager to change the existing deal with Oracle Data Pump, I have a meeting with them to keep my points and convence them for Oracle utility pump data.

    I have a week very convencing power but I won't miss to discover myself, I can't work myself and really a need with differences of strength against import and export, it would be really appreciated if someone can put strong points against Oracle Data pump on legacy import and export.

    Thank you

    Cabbage

    Hello

    a other people have already said the main advantage of datapump is performance - it is not just a little more fast exp/imp it is massively faster (especially when combined with parallel).

    It is also more flexible (once much more) - it will even create users with exports level schema which imp can't do for you (and it is very annoying that he could never).

    It is reusable

    It has an api plsql

    It supports all types of objects and new features (exp is not - and that alone is probably reason to spend)

    There even a 'legacy' at 11.2 mode where most of your old exp parameter file will still work with him - just change exp expdp and impdp print.

    The main obstacle to the transition to datapump seems to be all "what do you mean I have to create a directory so that it works", well who and where is my dumpfile why can't it be on my local machine. These are minor things to go well beyond.

    I suggest do you some sort of demo with real data of one of your large databases - do a full exp and a full expdp with parallel and show them the runtimes for them to compare...

    See you soon,.

    Rich

  • Groovy Script to find the difference between Dates

    I am trying to build a script that takes a date from a RequestField and calculates the number of days between this date and the current date (from session).

    So far, I have a problem, the analysis to-date from the RequestField chain. I found this code but it doesn't seem to work...

    date = new Date().parse('yyyy/MM/dd', '1973/07/09')
    

    I get the following error...

    Error Message: groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (java.lang.String, java.lang.String) values: {"yyyy/MM/dd", "1973/07/09"}
    

    Any help would be greatly appreciated.

    Hello

    What version of server? The extract you have here works fine on mine (563).

    This also works for me

    new java.text.SimpleDateFormat('yyyy/MM/dd').parse('1973/07/09')
    

    See you soon

    Nils

  • How to make the difference between data (different sensors and actuators) is tans/recvd using series com

    Hello

    I get 2 different types of data from the controller. How to differentiate b/w them.

    After receiving my code in deccissions. There are 6 different control elements in my project attached to the controller. Thanks for give me idea how I send data to the controller for this controller to differentiate that exit to be active or low

    First, look at the couple of serial examples that come with LabVIEW. You use the VISA functions to read and write. Your technique to separate the values will work as well in LabVIEW. You would be to convert the string returned by VISA reading to a digital (i.e. with the Scan of the chain). Then do the comparison, then the result of wire to one of the two indicators. Put the terminal of each indicator inside a case statement would be a way to do it.

  • BlackBerry Z10 difference between guest and the data service

    Hi all

    new user of the Z10, his job very well, I just had a small problem or issue. What is the difference between data services being on vs calls in roaming? I usually use wifi, but often the mode invite, can't do the acquisition of internet connection, even though I have the data service and a G full download available.

    Any help would be greatly appreciated!

    See you soon,.

    Excellent!

    Thanks for the reply "prompt"!

  • Differences between HA solutions

    Could someone explain the differences between Data Guard, Oracle Streams, and Golden Gate? One or two sentence will be enough.

    For comparison between Eve and streams, see MOS study between Oracle Streams and Oracle Data Guard (ID 300223.1)

    Water course has three phases: capture data to redo, to propagate data and apply the data on the destination. All these three work at the database level.

    Golden gate has three steps: Capture and delivery Manager. The capture is known as excerpt from process. the spread (delivery) of the data and apply data (manager) are carried out at the level of the BONE.

    but I still don't understand the differences between streams and the Golden Gate. Both are Oracle products and looks to do the same.

    Golden gate was a third-party solution for replication, which was recently taken over by Oracle Corp.
    (A very less amount of available on this article)

    Kind regards
    S.K.

  • difference between standard and non-standard

    Is there a difference between data standardized and not standardized? If there is, what is it?

    If I have understood the question, there is no difference between "nomalized' and 'not normalized. Based on the convenience is to denormalize the people change the words, the technical term.

    For more information search google on the denormalization, tons of items awaits you.

    -Madan

  • Difference between DAQmx DAQmx Base and acquisition of Legacy data

    Hello

    What is the difference between NI-DAQmx, DAQmxBase and acquisition of data Legacy and what are the characteristics of these materials

    See this FAQ.

    And it's the software, not hardware.

  • Difference between DAQ and DAQmx for acquisition of data PCI 6534

    Hello

    I use the PCI DAQ 6534 card for my digital I/o transfer. I am beginner in the labview.

    I want to store the data coming in memory and the reading of the data at the level of the trigger.

    I have seen the examples in the labview. Some have used DAQmx and DAQmx read write that screws and some have used the confg DIO port and all...

    So I want to know the difference between these two. For my application that I use?

    Hey Bo,

    First of all, I would recommend that you discover the NI 6533/6534 for NOR-DAQmx help. You may be able to find some of your answers in this help document. Now for what you try to do in your application, it looks like you are only buying data. If this is the case, with the 6534, the device acquires data in memory shipped as soon as the DAQmx series start task VI, as long as you don't start hardware triggers have in place. If you have a trigger of starting material, then will make the purchase of the aircraft after the DAQmx start task VI and only after you receive this material trigger. If you call not the DAQmx Read VI, then the data will be stored in the memory board for you, as the driver manages this data in the on-board memory storage, until reading DAQmx VI is called, which at that time, data is transferred to the Board of Directors in the memory of the computer. Once you get it in the computer's memory, you can do whatever you want with these data, as this graph or treat. If you look at the sample programs (which have been mentioned on how to find those in a previous post), you can find an example that little shows you how it works. One of the examples that you can check is called reading Dig Port-Ext Clk.VI. In this example, it sets up to read a finite number of samples and then starts the task. If you set a breakpoint on the line of the error after the VI begin, the data will be acquired in the amount of on-board memory. Then when you cancel the break of the VI, data will be extracted from the amount memory embedded in the memory system with the reading VI DAQmx. Again, the pilot takes care to put the data in the memory board for you once you start the task.

    I hope this helps. Please let us know if you have any questions or concerns about this issue. Also, certainly, discover and try to run all the programs related to the 6534 examples so that you can learn how the equipment works and how to use features to do what you want your program to do. Also, be sure to read through the help on the 6534, as well as the help of VI documentation to learn what makes each function. Thank you and have a nice day.

    Kind regards

    DJ L.

Maybe you are looking for