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?

Tags: Database

Similar Questions

  • 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...

  • 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.

  • 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
    
  • What is the difference between the type of table and view?

    Hello world.

    What is the difference between the type of view and table that we can set using SQL statement such as: "tab type is table of...» » ?

    A view is a stored query.

    An array type is a construction of PL/SQL.

    Both are documented:

    http://docs.Oracle.com/CD/E11882_01/server.112/e10897/schema.htm#ADMQS0841

    Management of schema objects

  • difference between materailized and a table

    Hey hiii

    I want to know what is a difference between a materialized view and that is to say a table suppose I create a table and another table B on the table, I created a trigger that will download all changes made to A, it IE insert, update or delete while it will perform all actions that a materialized view can perform on one or is there a difference between them



    Thks

    In this case, MView will be much more robust and reliable, because it is designed for that you use coding the trigger. You will manage all possible exceptions and lock the trigger claim everything is Oracle build-in MView. And also, MView can be much more powerful.

    Nicolas.

  • 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

  • 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

  • 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.

  • 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

  • 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')

  • Difference between an associative array, table etc.?

    Hello

    I wonder what are the differences in comparison with these? They seem similar, but a table need a custom c# and the associative array type class does not. When should you use that? Say I want to pass a collection of numbers to a perhaps stored procedure?

    You want to test something to appropriate for what your use to gauge that.

    I just did a quick test and associative is quite a bit faster than the UDT for my test regarding the disappearance of the object and the invocation of the proc (I went from size 1000 channels 2000), but I've also used an empty body of the stored procedure and the proc in fact might affect things.

    Here is my code if you want to test. I used ODT to generate the V2TYP class and then changed string [] m_V2TYP; to the public within this category just for ease of use.

    It will be useful,
    Greg

    /*
    create type v2typ is table of varchar2(4000);
     /
    create or replace package testpack as
    TYPE v2array is table of varchar2(4000) index by BINARY_INTEGER;
    PROCEDURE test_assoc_array(v2arr1 IN v2array);
    procedure test_udt(v2udt in v2typ);
    END;
    /
    CREATE or replace PACKAGE BODY testpack AS
    PROCEDURE test_assoc_array(v2arr1 IN v2array) IS begin null; END;
    procedure test_udt(v2udt in v2typ) is begin null; end;
    END;
    /
    */
    
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    namespace compare_assocarray_and_udt
    {
        class Program
        {
            static string constr = "data source=orcl;user id=scott;password=tiger;";
            static void Main(string[] args)
            {
                int numelements = 1000;
                string[] vals = new string[numelements];
                for (int i = 0; i < numelements; i++)
                    vals[i] = new string('a', 2000);
    
                V2TYP myv2typ = new V2TYP();
                myv2typ.m_V2TYP = vals;
    
                test_assoc_array(vals);
                test_udt(myv2typ);
            }
    
            static void test_assoc_array(string[] vals)
            {
                using (OracleConnection con = new OracleConnection(constr))
                {
                    con.Open();
    
                    using (OracleCommand cmd = new OracleCommand("testpack.test_assoc_array", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Varchar2);
                        Param1.Direction = ParameterDirection.Input;
                        Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
                        Param1.Size = vals.Length;
                        Param1.Value = vals;
                        DateTime start = System.DateTime.Now;
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("assoc array elapsed: {0}ms", (System.DateTime.Now - start).TotalMilliseconds.ToString());
                    }
                }
            }
    
            static void test_udt(V2TYP val)
            {
                using (OracleConnection con = new OracleConnection(constr))
                {
                    con.Open();
    
                    using (OracleCommand cmd = new OracleCommand("testpack.test_udt", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Object);
                        Param1.Direction = ParameterDirection.Input;
                        Param1.UdtTypeName = "SCOTT.V2TYP";
                        Param1.Value = val;
                        DateTime start = System.DateTime.Now;
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("udt elapsed:         {0}ms", (System.DateTime.Now - start).TotalMilliseconds.ToString());
                    }
                }
    
            }
        }
    }
    
  • 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.

Maybe you are looking for

  • Why my bookmarks bar does NOT show icons only even if I put up in this way in customize it drop down?

    I get 'icons and text' or 'text' but 'icons' just not displayed. You say that the default should be icons only, but this is not the case. What is a programming problem?

  • Games running in lower resolution on the desktop resolution does not fill the screen

    I have a laptop HP ENVY 17 TS with NVIDIA GT 740 M and Intel 4600HD graphics drivers and running Windows 7. Whenever I want to change the resolution in games at a lower resolution on the desktop resolution, the game shrinks to its view, leaving the c

  • Windows XP operating system

    I just bought a 2nd hand laptop that has Linux installed on it - I don't want to use linux and to switch to Windows XP, there is a sticker on the laptop to say there deition windows xp home is installed - the sticker is a license sticker - can I get

  • my version of bluetooth 62 227 10 shows disabled

    I'm so frustrated with bluetooth. One day it works, then, the next day, does not. When I click on 'my device' it shows "disabled" and address bluetooth like 0000000000000000 etc etc... Please can someone help... Thank you very much

  • Missing hard drive space

    Good afternoon... It seems that whenever I surf the web, watch a video on Youtube, etc., my temporary internet file is stored on my hard drive. I decided this because I run a security scan every time I find myself with the files of nearly 2 million s