Receive every month between date Range

Hi all

I said you want to display the month and year for the date range. IE Start date: 01-11-12, end Date: 31/05/13

SELECT COUNT(T1.CUST_NM) AS COUNT, TO_CHAR(T1.CREATE_DT,'MON-YY') AS MONTH, SUM(T3.DISBURSEMENT_LIMIT) AS TOTAL
  FROM CUSTOMER T1, 
 ACCOUNT T2, LOAN_ACCOUNT T3, CREDIT_APPL T4, PORTFOLIO T5 WHERE  T1.CUST_ID = T2.CUST_ID  AND T2.ACCT_ID = T3.ACCT_ID  AND T3.APPL_ID = T4.APPL_ID  AND 
 T4.PORTFOLIO_ID = T5.PORTFOLIO_ID
and t1.CREATE_DT between to_date('01-01-10','DD-MM-YY') and  to_date('30-12-10','DD-MM-YY') 
 GROUP BY TO_CHAR(T1.CREATE_DT,'MON-YY')




Exit SQL:

CountyMonth-yearTotal
8JAN-1015300
6FEB-104245000
11AUG-10144500
6DEC-1015500

Now SQL returns matching records to date. But the requirement is to display the name of the month, the number and total 0 if there is no data found.

Power required:

County Month-year Total
8Jan15300
1Feb-10118750
0March-100
0Apr-100
0May - 100
0Jun - 100
0Jul-100
11Aug-10144500
0Seven.-100
0Oct-100
0Nov - 100
6Dec - 1015500

Please suggest me SQL to archive the above of the requirement.

Thanks and greetings

Saami

Try this

with t

as

(

Select count (t1.cust_nm) as County

to_char(t1.create_dt,'mon-yy') per month

, sum (t3.disbursement_limit) total

the t1 client

in t2

loan_account t3

credit_appl t4

the t5 portfolio

where t1.cust_id = t2.cust_id

and t2.acct_id = t3.acct_id

and t3.appl_id = t4.appl_id

and t4.portfolio_id = t5.portfolio_id

and t1.create_dt between to_date ('01-01-10', ' dd-mm-yy')

and to_date ('30-12-10', ' dd-mm-yy')

Group

by to_char(t1.create_dt,'mon-yy')

)

t1

as

(

Select to_char (add_months (to_date('01-01-10','dd-mm-yy'), level-1), 'Mon - yy') month_list

of the double

connect

by add_months (to_date('01-01-10','dd-mm-yy'), level-1)<= >

)

Select nvl (t.count, 0) as County

t1.month_list per month

, nvl (t.total, 0), as total

from t1

left

Join t

on t1. month_list = t.month

Tags: Database

Similar Questions

  • to get the last date of every month between year 2000 to 2100

    Hi all

    How we can make this last list date of every month between 2000 and 2100

    Thanks and greetings
    Vivek

    You must use the LAST_DAY() function:

    WITH months AS
    (
         SELECT      TO_DATE('01/01/2000','MM/DD/YYYY') AS dt1
         ,     TO_DATE('12/31/2100','MM/DD/YYYY') AS dt2
         FROM     DUAL
    )
    SELECT LAST_DAY(ADD_MONTHS(dt1,level-1)) LST_DAY_MONTHS
    FROM     months
    CONNECT BY LEVEL <= MONTHS_BETWEEN(dt2,dt1)+1
    

    Sample of results (too many to display):

    LST_DAY_MONTHS
    -------------------
    01/31/2000 00:00:00
    02/29/2000 00:00:00
    03/31/2000 00:00:00
    04/30/2000 00:00:00
    05/31/2000 00:00:00
    06/30/2000 00:00:00
    07/31/2000 00:00:00
    08/31/2000 00:00:00
    09/30/2000 00:00:00
    10/31/2000 00:00:00
    11/30/2000 00:00:00
    12/31/2000 00:00:00
    01/31/2001 00:00:00
    02/28/2001 00:00:00
    03/31/2001 00:00:00
    04/30/2001 00:00:00
    05/31/2001 00:00:00
    06/30/2001 00:00:00
    07/31/2001 00:00:00
    08/31/2001 00:00:00
    09/30/2001 00:00:00
    10/31/2001 00:00:00
    11/30/2001 00:00:00
    12/31/2001 00:00:00
    01/31/2002 00:00:00
    02/28/2002 00:00:00
    03/31/2002 00:00:00
    
  • How to get LASTDAY for each month between data dates...

    Hi friend

    I have a doubt, how to get LASTDAY for each month between data dates...

    for ex:
    My contribution will be like this
    date = 01/12/2011
    To date = 14/04/2011

    And I need an output like
    31/01/2011
    28/02/2011
    31/03/2011

    is it possible to achieve through sql query in oracle
    Thanks in advance for all friends to help him

    Hello

    Something like this (assuming that the dates are originally VARCHAR2s):

    SQL> var dt_start varchar2(10)
    SQL> var dt_end varchar2(10)
    SQL> exec :dt_start := '12-01-2011'
    
    PL/SQL procedure successfully completed
    
    SQL> exec :dt_end := '14-04-2011'
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> select last_day(
      2           add_months(
      3             trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'),
      4             level-1
      5           )
      6         ) as result
      7  from dual
      8  connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY'))
      9  ;
    
    RESULT
    -----------
    31/01/2011
    28/02/2011
    31/03/2011
     
    

    If the dates are already of the date data type, simply remove the to_date function.

  • Show all dates between date range (time Dimension is left outer join)

    All,

    I did some research on this issue, but in all positions on date variables, date prompts and date filtering I have not seen one exactly to my question (perhaps that they are and I don't have my head around it properly yet).

    My requirement of report is to allow a user to select a start date and an end of day. The report is expected to show the activity of these two days - AND display 0/null on days where there is no activity. This second part is where I am getting hung up.

    The paintings in question are:
    Timedim
    EventFact
    CustomerDim

    My MDB is configured as follows:
    Left outer join of Timedim EventFact
    Inner join CustomerDim EventFact

    If I run a report by selecting the DAYS of Timedim and an EventFact measure1 with range day 01/01/2010-31/12/2010... A record for each day and it looks perfect because of the left outer join between Timedim and CustomerDim.

    But... If I add a CustomerDim field, Select TimeDim.DAY, CustomerDim.CUSTNAME, EventFact.MEASURE1, OBIEE returns only records for the days that have record EventFact.

    This is due to the fact that the Timedim is always external joined in EventFact, but adding in fact CustomerDim OBIEE set up an inner join between tables that will only return data where there are data EventFact.

    There is a way around it in this simple case, and that is to define the relationship between CustomerDim and EventFact as an outer join as well. This will give the desired effect (but an outer join between the two tables is not the real relationship) and I have add an extra dimension and add additional sources of logic to a single dimension in MDB it becomes complicated and messy.

    Also, ive ruined with the definition of the conduct in the relationship table, etc... but he gave not the desired effect.

    Has anyone ever met the need for force display all dates within a range specified with a fact table that does not have an entry for each date?

    Thanks in advance.

    K

    Published by: user_K on April 27, 2010 11:32

    Hi there, the easiest way is to the LTS himself. Double-click your LTS, go to the tab with the column mappings. Make sure you have checked "show no mapped" column.

    You should see your new dummy column in the list, in the central part of mapping (IE not the right) just enter 0, or launch the expression editor and enter 0 in there.
    simple!

  • Split line based on the date range

    Hello
    Can someone help me on how to write SQL for power condition
    I have some files like this
    SERVICE SELECTION     SO     BUILDINGNAME                DT1                DT2               DOLLAR
    
    36002845             BAS     15 - 17 HUNTSWORTH MEWS     01-12-2004     30-11-2005     21942
    36007029             BAS     15 - 17 HUNTSWORTH MEWS     01-12-2006     30-11-2007     2101
    I would like to divide the lines above according to t1d and T2D
    For example the first record I want to split into 12 lines IE a line for every month between (2004-12-11-2005)
    Second disc I'd divided in 11 lines, that is to say a line for every month between (12-2006 to 10-2007)

    Thanks in advance
    Concerning
    Prabahar

    KKP wrote:
    Hello
    Can someone help me on how to write SQL for power condition
    I have some files like this

    SERVICE SELECTION     SO     BUILDINGNAME                DT1                DT2               DOLLAR
    
    36002845             BAS     15 - 17 HUNTSWORTH MEWS     01-12-2004     30-11-2005     21942
    36007029             BAS     15 - 17 HUNTSWORTH MEWS     01-12-2006     30-11-2007     2101
    

    I would like to divide the lines above based on t1d and T2D
    For example the first record I want to split into 12 lines IE a line for every month between (2004-12-11-2005)
    Second disc I'd divided in 11 lines, that is to say a line for every month between (12-2006 to 10-2007)

    Not very well why you say that you get only 11 lines for the second record that goes up to 11-2007 No 10-2007 as you suggest.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 36002845 as service_selection, 'BAS' as so, '15 - 17 HUNTSWORTH MEWS' as buildingname, to_date('01-12-2004','DD-MM-YYYY') as dt1, to_date('30-11-2005','DD-MM-YYYY') as dt2, 21942 as dollar from dual union all
      2             select 36007029, 'BAS', '15 - 17 HUNTSWORTH MEWS', to_date('01-12-2006','DD-MM-YYYY'), to_date('30-11-2007','DD-MM-YYYY'), 2101 from dual)
      3  -- end of test data, use query below
      4  select t.service_selection, so, buildingname, add_months(dt1, rn) as dt, dollar
      5  from t,
      6       (select rownum-1 as rn
      7        from dual
      8        connect by rownum <= (select max(months_between(dt2, dt1))+1 from t))
      9  where add_months(dt1,rn) <= dt2
     10* order by 1, 4
    SQL> /
    
    SERVICE_SELECTION SO  BUILDINGNAME            DT             DOLLAR
    ----------------- --- ----------------------- ---------- ----------
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-12-2004      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-01-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-02-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-03-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-04-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-05-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-06-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-07-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-08-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-09-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-10-2005      21942
             36002845 BAS 15 - 17 HUNTSWORTH MEWS 01-11-2005      21942
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-12-2006       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-01-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-02-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-03-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-04-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-05-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-06-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-07-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-08-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-09-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-10-2007       2101
             36007029 BAS 15 - 17 HUNTSWORTH MEWS 01-11-2007       2101
    
    24 rows selected.
    
    SQL>
    
  • Assign months within a range of dates (by almost every day in a given month)

    I have a date beginning and end, the sample data as well

    Select to_date('01-13-12','mm-dd-yy') from_dt,
    to_date('02-23-12','mm-DD-yy') to_dt
    of the double
    Union of all the
    Select to_date('03-15-2012','mm-dd-yy') from_dt,
    to_date('04-16-2012','mm-DD-yy') to_dt
    of the double
    Union of all the
    Select to_date('05-13-2012','mm-dd-yy') from_dt,
    to_date('07-23-2012','mm-DD-yy') to_dt
    of the double

    How can I assign a month by most of the days in a month in this date range? Sometimes the date range can be exactly as many days in a month (as the 15/03/2012 has 16 days and 16/04/2012 16 days). In this case, I want to than the previous month (March).

    So according to the data of the sample:

    13/01/2012, 23/02/2012, February
    15/03/2012, 16/04/2012, March
    13/05/2012, 23/07/2012, June

    Thank you

    Published by: user4422426 on March 1, 2012 17:15

    Hello

    Here's one way:

    WITH     cntr          AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (
                   SELECT      1 + MAX (to_dt - from_dt)     AS max_day_cnt
                   FROM     table_x
              )
         CONNECT BY     LEVEL     <= max_day_cnt
    )
    ,     got_r_num     AS
    (
         SELECT     x.from_dt, x.to_dt
         ,     TRUNC (x.from_dt + c.n, 'MONTH')     AS month
         ,     count (*)                    AS cnt
         ,     ROW_NUMBER () OVER ( PARTITION BY  from_dt, to_dt
                             ORDER BY        COUNT (*)     DESC
                             ,             TRUNC (x.from_dt + c.n, 'MONTH')
                           )     AS r_num
         FROM       cntr     c
         JOIN       table_x  x  ON  c.n  <= x.to_dt - x.from_dt
         GROUP BY  x.from_dt, x.to_dt
         ,       TRUNC (x.from_dt + c.n, 'MONTH')
    )
    SELECT     from_dt, to_dt
    ,     TO_CHAR (month, 'Mon YYYY')     AS mon
    ,     cnt
    FROM     got_r_num
    WHERE     r_num     = 1
    ;
    

    Thanks for posting the code to create the same data. Test your code before you post: you've got the reverse order of the arguments to TO_DATE.

  • SQL to generate the intervals from date of 6 months each, between two date ranges

    Hi all

    I looked in the forums, if someone uses CREATE_CHUNKS_BY_SQL for dates, but no luck.
    I want to update a table using pieces of dates.
    I need to generate date ranges to divide them by pieces.

    I have a table where I know that max (sales_date) and min (sales_date).
    Lets say max (sales_date): min (sales_date) 01/01/2008: 31/10/2010

    I want to break in intervals of 6 months (180 days) as below:
    chunk_id     start_date     end_date
    --------     ----------     --------
      1          01/01/2008     06/30/2008
      2          01/07/2008     12/31/2008
      3          01/01/2009     06/30/2009
      4          01/07/2009     12/31/2009
      5          01/01/2010     06/30/2010
      6          01/07/2010     10/31/2010
    He didn't exactly finish end of the month. Basically, I need these beaches of dates at apart 180 days.

    I appreciate if someone can throw some ideas on this.

    Thank you
    Raj.

    Hi, Raj,

    Sorry, it is unclear what you are asking.

    To generate a list of dates starting with min_sales_date and including all the 180 days after that up to (but not beyond) max_sales_date:

    WITH     got_params     AS
    (
         SELECT     DATE '2008-01-01'     AS min_sales_date
         ,     DATE '2010-10-31'     AS max_sales_date
         FROM     dual
    )
    SELECT     min_sales_date + (180 * (LEVEL - 1))     AS grp_start_date
    FROM     got_params
    CONNECT BY     LEVEL <= CEIL ( ( (max_sales_date - min_sales_date)
                                    + 1
                           )
                         / 180
                         )
    ;
    

    Output:

    GRP_START_D
    -----------
    01-Jan-2008
    29-Jun-2008
    26-Dec-2008
    24-Jun-2009
    21-Dec-2009
    19-Jun-2010
    

    December 16, 2010 is 180 days after June 19, 2010, but it is not displayed, because is after max_sales_date, which is 31 October 2010.

    I hope this helps you.
    Whenever you have any questions, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.

  • How to display each month between the date range

    I want a query that gives me the number of months between two dates given for example, if I going January 1, 2009 and April 1, 2009 then I should get on February 1, 2009 and March 1, 2009 in my trips

    Thank you very much

    Srix wrote:
    Thanks for the request

    It is not working do not when the effective date is differs from that in a year i.e start date January 1, 2009 and end date February 1, 2009, that it does not give u then required result

    I don't know what you mean? The dates are in the same year.

  • Insert record monthly between certain dates

    Hi all

    Any help is very appreciated.

    I would like to add records to a table every month according to certain dates. So I'll have a start_date and end_date and I would like to add a record to a table the 1st of each month between these two dates.

    Can you please let me know what would be the best way to address the issue and give an example of the code please.

    Thank you

    Hello

    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    If you ask on a DML statement, such as CREATE TABLE, INSERT, INSERT statements must re-create the tables as they are to the DML, and the results will be the content of the or a modified tables when it's all over.
    Always tell what version of Oracle you are using.

    Here's one way:

    INSERT INTO table_x (due_date)
    WITH    parameters  AS
    (
         SELECT     DATE '2011-10-01'     AS start_date
         ,     DATE '2012-03-31'     AS end_date
         FROM     dual
    )
    SELECT     ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                  , LEVEL - 1
                 )
    FROM    parameters
    WHERE     ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                  , LEVEL - 1
                 ) >= start_date
    CONNECT BY     LEVEL     <= 1 + MONTHS_BETWEEN ( TRUNC (end_date,   'MONTH')
                                          , TRUNC (start_date, 'MONTH')
                                   )
    ;
    
  • Need to query to find missing months between two dates.

    A bank customer a monthly overview of databases (in the tens of millions of accounts)

    The data are sent with a line per account each month.  It is stored in a table called "ACCOUNTS_TAB".

    Fields on registration, which

    Column

    Description

    Example of format.

    * YRMTH-1

    Year and month of the snapshot

    6-character numeric, 4-digit year added to months of 2 digits, example 201301, 201311

    * AccountID

    Unique identifier for an account.

    Integer, example 100098322

    Opening balance - 1

    Initial account balance at the closing of the previous month

    $30000

    Closing balance - 1

    The account balance at the end of the month of closing

    $34200

    Class-1 relative to investments

    .....

    ...

    .....

    ......

    .....

    Many more columns, two favorites (*) columns are alone, that you will need for the query. There are no columns to tell when an account is closed, or has just opened, and not separate "master account" - you use this single table for your query that results.

    The table was in place from 200301, so many accounts have dozens of lines, if they have been open for many years and other only 1 or 2 ranks, if new.

    Write a query to give just a list of accountDs that meet the following criteria.

    1. 1) has a record for specific 201503
    2. 2) was also a record for the month specific 201602
    3. 3) missing one or several months between these two records.

    A good account which was opened from 201503 to 201602 inclusive would of course have lines for

    201503

    201504

    201505

    201506

    201507

    201508

    201509

    201510

    201511

    201512

    201601

    201602

    It's good to hardcode the month of departure (201503), end of month (201602) and the actual number of months between them (10 exclusive or 12 inclusive) as part of your query.

    Once again the account must meet all 3 criteria to be an account issue.  If only, they have a partial set of these documents but do not have the month of departure, or is not the end of the month, it is not a problem, only when they have so specified and end early and not a full between game.


    Help, please!

    Maybe this...

    -----

    -The Dataset for the test begins

    WITH dataset (ACCOUNT_NO, DATES)

    AS (SELECT 100, DOUBLE 201503

    UNION ALL

    SELECT 100, DOUBLE 201504

    UNION ALL

    SELECT 100, DOUBLE 201505

    UNION ALL

    SELECT 100, DOUBLE 201506

    UNION ALL

    SELECT 100, DOUBLE 201507

    UNION ALL

    SELECT 100, DOUBLE 201508

    UNION ALL

    SELECT 100, 201509 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201510

    UNION ALL

    SELECT 100, 201511 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201512

    UNION ALL

    SELECT 100, 201601 DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201602

    UNION ALL

    SELECT 200, DOUBLE 201503

    UNION ALL

    SELECT 200, DOUBLE 201504

    UNION ALL

    SELECT 200, DOUBLE 201505

    UNION ALL

    SELECT 200, DOUBLE 201506

    UNION ALL

    SELECT 200, DOUBLE 201508

    UNION ALL

    SELECT 200, DOUBLE 201509

    UNION ALL

    SELECT 200, DOUBLE 201510

    UNION ALL

    SELECT 200, DOUBLE 201511

    UNION ALL

    SELECT 200, DOUBLE 201512

    UNION ALL

    SELECT 200, 201601 DOUBLE

    UNION ALL

    SELECT 200, DOUBLE 201602

    UNION ALL

    SELECT 300, DOUBLE 201503

    UNION ALL

    SELECT 300, DOUBLE 201504

    UNION ALL

    SELECT 300, DOUBLE 201505

    UNION ALL

    SELECT 300, DOUBLE 201506

    UNION ALL

    SELECT 300, DOUBLE 201507

    UNION ALL

    SELECT 300, DOUBLE 201508

    UNION ALL

    SELECT 300, DOUBLE 201509

    UNION ALL

    SELECT 300, DOUBLE 201510

    UNION ALL

    SELECT 300, DOUBLE 201511

    UNION ALL

    SELECT 300, 201601 DOUBLE

    UNION ALL

    SELECT 300, DOUBLE 201602

    UNION ALL

    SELECT 400, DOUBLE 201504

    UNION ALL

    SELECT 400, DOUBLE 201505

    UNION ALL

    SELECT 400, DOUBLE 201506

    UNION ALL

    SELECT 400, DOUBLE 201507

    UNION ALL

    SELECT 400, 201508 DOUBLE),

    -The Dataset to test ends

    -Hand with clause begins

    ResultSet

    AS (SELECT account_no,

    CASE

    WHEN COUNT)

    CASE WHEN dates IN (201503, 201602) THEN 1 END)

    COURSES (PARTITION BY account_no) = 2

    AND (COUNT (DISTINCT SUBSTR (dates, 4)))

    COURSES (PARTITION BY account_no) = 12

    OR COUNT (DISTINCT SUBSTR (dates, 4))

    COURSES (PARTITION BY account_no)<>

    AND COUNT (DISTINCT SUBSTR (dates, 1, 4))

    (PARTITION BY account_no) > 1

    THEN

    « Y »

    ON THE OTHER

    « N »

    END

    FLG

    THE dataset---> replace with your table name

    GROUP BY account_no, dates)

    SELECT DISTINCT Account_no

    FROM THE result set

    WHERE flg = 'Y ';

    -Hand with the ends of the clause

    ACCOUNT_NO

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

    100

    300

    200

    See you soon,.

    Manik.

  • Generating lines separated for each month in a date range

    Basically I have a row of data, for example:

    ID - start_date - end_date

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

    XXA 1/23/14-3/12/14

    And I want to create a line for each month between the arguments start_date and end_date, for each ID, for example:

    ID - month - year

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

    XXA January 2014

    XXA February 2014

    XXA March 2014

    What is the best and most effective way to do it? I thought using a slider, but once the table is created, I need to join the other than this one. I am new to oracle, and I don't know if you can join the other tables after completing a cursor and create a temporary table. Any help would be greatly appreciated.

    so... go with this:

    WITH DATA AS (SELECT "XXA' ID, DATE '2014-01-23' start_date, DATE' 2014-12-03' end_date FROM dual)

    UNION ALL

    SELECT "XX(B)' ID, DATE '2013-05-23' start_date, DATE' 2014-07-03' end_date dual FROM

    UNION ALL

    SELECT "XXC" ID, DATE '2012-01-23' start_date, DATE' 2013-12-03' end_date FROM dual)

    minmax AS (SELECT MIN (TRUNC(START_DATE,'Month')) AS minmon

    MAX (trunc(end_date,'Month')) AS maxmon

    DATA)

    , themons AS (SELECT add_months (minmon, LEVEL - 1) LIKE my)

    OF minmax

    CONNECT BY add_months (minmon, LEVEL - 1)<=>

    SELECT d.id, m.mon

    DATA d

    JOIN themons m ON (m.mon BETWEEN trunc(d.start_date,'Month') AND trunc (d.end_date, 'Month'))

    order by d.id, m.mon

    /

  • Months between two dates

    Hello

    I have two dates. start date and end date.

    I want to extract months between two dates

    months should be as

    JAN

    FEB

    MAR

    for example.

    Start - 1-jan-2014

    date of end - 31 - dec - 2014

    How can I do this?

    Thanks and greetings

    CORINE

    You should always use the function MONTHS_BETWEEN...

    for example

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5. Select to_char (add_months (start_date, rownum-1), 'My') by month
    6 t
    7 * connect by rownum<=>
    SQL > /.

    LUN
    ---
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Ms
    Oct
    Nov
    Dec

    12 selected lines.

    And if you want that they display, separated by commas...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5 Select listagg (to_char (add_months (start_date, rownum-1), 'My'), ',') group by month (order by rownum)
    6 t
    7 * connect by rownum<=>
    SQL > /.

    MONTH
    -----------------------------------------------------------------------------------------------------------------
    Jan, Feb, Mar, Apr, may, June, July, August, Sept, Oct, Nov, Dec

  • How to get the second Monday of each month in a given date range?

    In Oracle forms, how to get the second Monday of each month in a given date range?

    I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?

    WITH month_range AS

    (

    SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month

    , TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month

    OF the double

    )

    SELECT NEXT_DAY (6 + ADD_MONTHS (first_month

    , LEVEL - 1

    )

    , 'MONDAY '.

    ) AS second_monday

    OF month_range

    CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)

    ;

    Thanks in advance.

    Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.

    THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7

    END AS second_day

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • How to calculate the number of days/weeks/months between 2 dates?

    Hello

    I would like to know how to calculate the number of days/weeks/months between 2 dates in OBIEE 11 g, for example, I have 26/05/2013 and 19/05/2013, then I want to get 7 days.

    Thank you!
    Jamie

    Hi Jamie,

    Through this links...

    http://www.bravesoft.com/blog/?p=682
    http://twobiee.blogspot.in/2012/01/working-with-date-differences.html

    Mark as correct it allows u...
    Thank you...

  • Get the number of months between the dates.

    Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?

    876056 wrote:
    Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?

    I don't see how you get 8.4 months. The counted months are February, March, April, may, June, July, August and, as of today, 9 and change the days of September. Unless I forgot the lessons of counting, I learned in kndergarten is 7 full months and a bit.

    Maybe you want something like:

    SQL> select months_between(Sysdate, to_date('01-JAN-2011', 'dd-mon-yyyy')) mb,
      2         (Sysdate - to_date('01-JAN-2011', 'dd-mon-yyyy'))/30 div30
      3  from dual;
    
            MB      DIV30
    ---------- ----------
    8.27800142 8.38726813
    

    If you get the form date a table, you can use trunc (date_column, 'mm') at the date of the first day of the month.

    John

Maybe you are looking for

  • We cannot send or receive emails via our server. We use Outlook Express.

    This is the Outlook Express message give me: Your server suddenly put an end to the connection. The possible causes for this include server problems, network problems, or a long period of inactivity. Account: 'rawlfarms.com', server: 'rawlfarms.com',

  • Dell Inspiron 17R laptop computer stand

    Help!  I have trouble finding a laptop computer support who will properly hold my Dell Inspiron 17R, especially at the front.  Recommendations, please?  I would be * extremely * grateful.

  • Are there any recent "updates" which could slow down my computer?

    I had my system set up so that I would be informed of updates then I would elect to install those that I wanted too. Somehow this setting has been changed to automatically download and install updates. In recent weeks, I noticed that my computer has

  • BlackBerry smartphones can not get Livestrong on the new phone.

    First step: right here go us... go a Pearl of blackberry replacement and want to get the livestrong on this calorie counter.  Already purchased through paypal with my old phone in June.  On my new phone go to My App World, he's not here, there, I'm t

  • HotSync file location

    I've recently updated to Windows Vista and Desktop 6.2. Previously, I had put the location of my data files by going to tools | Options and the general tab. I don't see this option now. How can I set the location of my data files of the HotSync. Than