Get each end calendar month using SQL date

Hi guys,.

How to get the each month end date using SQL Script?

Ex: If the effective date is January 15, 2011, then the date will be January 31, 2011.

can someone help me get this result?


TIA,

Hello
I think that below query is useful for you.

Select last_day (Your_Date) of double;

Kind regards
Fame

Tags: Database

Similar Questions

  • get all the date of end of months between two dates

    Hi all, I'll try to find together the date of end of months between two dates.
    I have the following data in a table

    WITH AS's Data1
    (
    SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL
    SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, "TEST2" lname FROM dual UNION all
    SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, "TEST3" lname FROM dual UNION all
    SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, "TEST4" lname FROM dual UNION all
    SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, "TEST5" lname FROM dual UNION all
    SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, "TEST6" lname FROM dual UNION ALL
    SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all
    SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual

    )

    I would like to write an application that gives you all the end date for months between two dates
    for example, if you give the date 9/1/4 and 5/6/9, the output should be
    DT          LNAME
    -------------------
    4/30/2009   TEST
    IF I give you the dates 01/04/09 AND 01/06/09, THEN output should be
    DT          LNAME
    -------------------
    4/30/2009   TEST
    5/31/2009   TEST7
    as you can see, I want all the end dates of months between two dates by giving the output.

    If I give you 06/05/09 and 05/06/09, and then does so no output because there is no end of month between these two dates.
    Similarly, if I give you 30/04/09 and 30/04/09 then output should be 30/04/09 because it is an end of month date

    anyone can help to write a query. Thank you very much

    Jin
    Not sure if you need subquery, analytical functions for this.
    According to me, which should solve your purpose.

    WITH data1 AS
    (
    SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL
    SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, 'TEST2' lname FROM dual UNION all
    SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, 'TEST3' lname FROM dual UNION all
    SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, 'TEST4' lname FROM dual UNION all
    SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, 'TEST5' lname FROM dual UNION all
    SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, 'TEST6' lname FROM dual UNION ALL
    SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all
    SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual 
    
    )
    select distinct last_day(dt) dt,lname
      from data1
     where dt between &start_date and &end_date
       and last_day(dt) <= &end_date
    
    also, i have another request. how would i do this without using the data i provided. lets say,
     i tell you, give me alll the months end between two dates using dual in the from clause of a query.
    how would you do this in a query or pl/sql? thanks again
    

    Can be like that

    with data1 as(
    select &start_date+level-1 dt from dual
    connect by level <= &end_date-&start_date+1)
    select distinct last_day(dt)
      from data1
     where dt between &start_date and &end_date
       and last_day(dt) <= &end_date
     order by last_day(dt)
    

    See you soon!
    Bobin

    Published by: Buga added query for updated the need

  • How to view this calendar of the current month using SQL code

    Hello

    I have a problem with the creation of a timetable for this month. Without any pl/sql program. Only by using sql.
    Please help me... !!


    Concerning
    Evelyne

    Hello

    Try this... It works...: D

         with x
               as (
            select *
              from (
            select to_char(trunc(sysdate,'mm')+level-1,'iw') wk,
                   to_char(trunc(sysdate,'mm')+level-1,'dd') dm,
                   to_number(to_char(trunc(sysdate,'mm')+level-1,'d')) dw,
              to_char(trunc(sysdate,'mm')+level-1,'mm') curr_mth,
                   to_char(sysdate,'mm') mth
             from dual
            connect by level <= 31
                  )
            where curr_mth = mth
           )
           select max(case dw when 2 then dm end) Mo,
                  max(case dw when 3 then dm end) Tu,
                  max(case dw when 4 then dm end) We,
                  max(case dw when 5 then dm end) Th,
                  max(case dw when 6 then dm end) Fr,
                  max(case dw when 7 then dm end) Sa,
                  max(case dw when 1 then dm end) Su
             from x
            group by wk
            order by wk
         
    

    concerning
    K

  • 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

  • Gets the number of months to a Date

    Hello

    I use the version of database Oracle 11.2.1. I would like to calculate the number of fiscal month of a date.

    For example:

    Date: 31/03/2013
    Fiscal No. month: 12

    The fiscal year runs from 01 - Apr-31 - March each year.

    Hello

    You can use

    EXTRACT (MONTH FROM (ADD_MONTHS (mydate, -3)))
    

    Example:

    WITH mytable AS (    SELECT TRUNC(SYSDATE) - 400 + LEVEL mydate
                           FROM DUAL
                     CONNECT BY LEVEL <= 400)
    SELECT mydate, EXTRACT (MONTH FROM (ADD_MONTHS (mydate, -3))) fiscal_month
      FROM mytable
     WHERE mydate = TRUNC (mydate, 'MM')
        OR mydate = LAST_DAY(mydate);
    
    MYDATE    FISCAL_MONTH
    --------- ------------
    31-MAR-12           12
    01-APR-12            1
    30-APR-12            1
    01-MAY-12            2
    31-MAY-12            2
    01-JUN-12            3
    30-JUN-12            3
    01-JUL-12            4
    31-JUL-12            4
    01-AUG-12            5
    31-AUG-12            5
    01-SEP-12            6
    30-SEP-12            6
    01-OCT-12            7
    31-OCT-12            7
    01-NOV-12            8
    30-NOV-12            8
    01-DEC-12            9
    31-DEC-12            9
    01-JAN-13           10
    31-JAN-13           10
    01-FEB-13           11
    28-FEB-13           11
    01-MAR-13           12
    31-MAR-13           12
    01-APR-13            1
    

    Kind regards.
    Al

  • Adobe Stock going by calendar month or the date of registration to download the Image 10?

    Hello

    I just signed, uploaded 10 images between 2/12-2/29, then tried to download more today and could not.

    Adobe uses the months of the calendar from the Date of registration to decide when to expire the 10 free downloads.

    Hello

    This is the date of the sign.  However, you seem to have used your 10 February image allowance so that can purchase individual images or wait until the date of renewal for your new allocation.

    Thank you

    Bev

  • Recover data from the subject of BAM using SQL Data Table

    Hi all


    If we create BAM SCARE that say XXEmployee _XXEmployee corrosponding BAM architect table would be created in the schema ORABAM.

    If I ask... Select * from XXEmployee, I get error saying this is not a valid identifier (table coz name is from a " " "").

    No idea how to extract data from BAM PERFORM using the Sql query.

    Thank you
    AB

    Hi AB
    I'm not the best oracle dba, so I don't know if the version makes a difference.
    I use this query on 10gr 2 in SQLPLUS (make sure you have quotation marks around table names)
    for example, BAM comes with a sample 'Employees' data object, I can do via sqlplus
    Select * from ORABAM. "" _Employees;

  • How to get the days and months when two dates are given

    Hi all

    I have a requirement where I need to return the number of months and days between two given dates.
    I have no need to take account of the year as the difference in dates is always less than a year

    I have 28 June 2012 and January 31, 2013, as dates.

    I'm working on 10g

    When I select the double months_between(:a,:b) and provide the dates he gives me 7.09677
    I want to give only 7 months and 9 days, or what ever the exact days are.

    Your contributions are appreciated

    Try this:

    WITH t AS
    (SELECT TO_DATE('28-JUN-2012', 'DD-MON-YYYY') date1, TO_DATE('31-JAN-2013', 'DD-MON-YYYY') date2 FROM dual)
    SELECT TRUNC(MONTHS_BETWEEN(date2, date1)) months,
           date2 - ADD_MONTHS(date1, TRUNC(MONTHS_BETWEEN(date2, date1))) days
    FROM   t
    
  • Retrieve the month following the date

    Hi people,

    How can I get the part of months to a date.

    Say, like, I want to get the month part (April = 4) 01/04/2009.

    Thanks in advance!

    Hello

    You can get all parts of a DATE using TO_CHAR.
    For example, on April 1, 2009

    SELECT  TO_CHAR (SYSDATE, 'Month')
    FROM    dual;
    

    product of the results of this

    April
    

    (if you use English) and

    SELECT  TO_CHAR (SYSDATE, 'MM')
    FROM    dual;
    

    produces this output (VARCHAR2)

    04
    
  • Use SQL statements to roll a calendar forward to a random date

    Hello

    Oracle 10.2.0.4 Linux

    We have two tables largeish (10 ^ 5 rows each) who follow our planned workforce hours.  The first table created generic programs that show the days, at that each must have Schedule 1-n lines in this document, one for every day of the cycle.  The majority of our workforce is on a 8 day cycle.  In the example below, I have two shifts

    Sched_4d it is a cycle of four days from the day - the day pairs off.

    Sched_3d cycle this is a full day off, half day, day off.

    According the information below you can see that in 1990, the sched_4d went to a day of 8 hours to 9 hours a day.  There is no guarantee that SCHED_4D will not win suddenly 2 additional days in this years union negotiations.

    The second table is a simple assignment table when a person goes on a calendar.

    To determine the schedule for the day a datum, you look at the table EMP_SHIFT to determine which calendar is 'in progress', then you look at the date at which the person has been assigned to the planning and guess that's SHIFT_ID 1, the next day is SHIFT_ID 2 until complete you the cycle and try again.

    CREATE TABLE SCHED_DATA

    (

    SCHED_ID VARCHAR2 (8 CHAR) NOT NULL,

    ASOFDATE DATE NOT NULL,

    SHIFT_ID NUMBER (3) NOT NULL,

    SCHED_HRS NUMBER (4,2) NOT NULL

    )

    ;

    CREATE UNIQUE INDEX SCHED_DATA on SCHED_DATA (SCHED_ID, ASOFDATE, SHIFT_ID)

    ;

    CREATE TABLE EMP_SHIFT

    (

    EMPID VARCHAR2 (15 CHAR) NOT NULL,

    ASOFDATE DATE NOT NULL,

    SCHED_ID VARCHAR2 (8 CHAR) NOT NULL

    )

    ;

    CREATE UNIQUE INDEX EMP_SHIFT on EMP_SHIFT (EMPID, ASOFDATE, SCHED_ID)

    ;

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1980 ', 1, 8);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1980 ', 2, 0);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1980 ', 3, 8);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1980 ', 4, 0);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1990 ', 1, 9);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1990 ', 2, 0);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1990 ', 3, 9);

    INSERT INTO SCHED_DATA VALUES ('SCHED_4D', 1 JANUARY 1990 ', 4, 0);

    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', 1 JANUARY 1990 ', 1, 8);

    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', 1 JANUARY 1990 ', 2, 4);

    INSERT INTO SCHED_DATA VALUES ('SCHED_3D', 1 JANUARY 1990 ', 3, 0);

    INSERT INTO EMP_SHIFT VALUES ('001', 20 DECEMBER 1989', 'SCHED_4D');

    INSERT INTO EMP_SHIFT VALUES ('001', 1 JANUARY 1990', 'SCHED_4D');

    INSERT INTO EMP_SHIFT VALUES ('001', 3 JANUARY 1990', 'SCHED_3D');

    In view of the above, I need to write a select statement receives 2 dates (: of and: to) and for all employees of EMP_SHIFT returns one row for each day and the hours for that day.

    Thus, the data above with one and from 21 December 1989 ': 5 January 1990 ' should return

    EMPID, DATE, SCHED_HOURS

    001, 21 - DEC, 0

    001, 22 - DEC 8

    001, 23 - DEC, 0

    001, 24 - DEC 8

    001, 25 - DEC, 0

    001, 26 - DEC 8

    001, 27 - DEC, 0

    001, 28 - DEC 8

    001, 29 - DEC, 0

    001, 30 - DEC 8

    001, 31 - DEC, 0

    001, 01 - JAN 9

    001, 02 - JAN, 0

    001, 03 - JAN 8

    001, 04 - JAN 4

    001, 05 - JAN, 0

    The employee began thir mission to sched_4d the 20 - DEC, then it would be SHIFT_ID 1.  DEC 21 - Therefore SHIFT ID 2, which is 0 hours.  Cycle until the next event which is 01 - JAN, when they are assigned to the new sched_4d who work 9 hours on day 1.  03 - JAN they pass to the new cycle and go to the 8:4:0 rotation.

    I can see how I could

    SELECT EMPID, DAY_OF_INTEREST, SCHED_ID

    EMP_SHIFT a, (SELECT 1 January 1979 ' + rownum 'DAY_OF_INTEREST' from dual connect by level < = 10000)

    WHERE A.ASOFDATE = (SELECT MAX (A1. ASOFDATE) OF A1 EMP_SHIFT WHERE A1. EMPID = A.EMPID AND A1. ASOFDATE < = DAY_OF_INTEREST)

    AND DAY_OF_INTEREST BETWEEN: FROM_DT AND: TO_DT

    And I guess I need to use some kind of MOD ((DAY_OF_INTEREST - EMP_SHIFT. ASOFDATE), (#number of days of shift)) which shift_id applies to a given Day_of_interest

    But I'm struggling to do this in a way that could evolve to more than one employee,

    The analytical functions achieve neatly?

    Hello

    There are several analytical functions that might help here.  Two tables include only; departure dates we need to know the end dates of both employee assignments regarding schedules.  I used the analytical functions MIN and LEAD to get these in the query below.  In addition, the following query needs to know how many days is in each Annex.  I used the analytical COUNT function for that.

    WITH params AS

    (

    SELECT TO_DATE (December 21, 1989 ","DD_MON-YYYY"") AS start_date

    , TO_DATE (5 January 1990 ', 'DD_MON-YYYY') AS end_date

    OF the double

    )

    all_dates AS

    (

    SELECT the LEVEL - 1 AS a_date + start_date

    OF params

    CONNECT BY LEVEL<= (end_date="" +="" 1)="" -="">

    )

    sched_data_plus AS

    (

    SELECT sched_id, asofdate, shift_id, sched_hrs

    NVL (MIN (asofdate) over (PARTITION BY sched_id

    ORDER BY asofdate

    RANGING FROM 1 TO MORE

    AND UNBOUNDED FOLLOWING

    ) - 1

    , TO_DATE (31-DEC-9999', 'DD-MON-YYYY')

    ) AS uptodate

    , COUNT (*) OVER (PARTITION BY sched_id

    asofdate

    ) AS days_in_sched

    OF sched_data

    )

    emp_shift_plus AS

    (

    SELECT empid, asofdate, sched_id

    NVL (in ADVANCE (asofdate) OVER (PARTITION BY empid

    ORDER BY asofdate

    ) - 1

    , TO_DATE (31-DEC-9999', 'DD-MON-YYYY')

    ) AS uptodate

    Of emp_shift

    )

    SELECT e.empid

    d.a_date

    s.sched_hrs

    Of all_dates d

    JOIN the s sched_data_plus WE d.a_date BETWEEN s.asofdate

    AND s.uptodate

    JOIN e-emp_shift_plus WE d.a_date BETWEEN e.asofdate

    AND e.uptodate

    AND e.sched_id = s.sched_id

    AND MOD (d.a_date - e.asofdate)

    s.days_in_sched

    ) + 1 = s.shift_id

    ORDER BY e.empid

    d.a_date

    ;

    This request is started by getting daily interest, that is, every day between the given - start and end dates.  (When you said "random date", I assume you meant 'a date', data which may not involve any random element.)

    Once we have a list of all the dates of interest, to get the results you want is just a matter of inner join to get the schedules were in effect on these dates, and which employees were assigned to these annexes to these dates.

    If you are worried about having more than 1 employee, maybe you should post the sample data that has more than 1 employee.

    How do you manage the endings of the employee?  For example, what happens if the employee 001 had left on January 4, 1990?  I guess that you would like the output for this employee stop January 4, rather than continue to the end of the period that interests us.

    If you have dates of termination in an employee table not shown here, then you can use this date of termination instead of December 31, 9999 as the end date by default of the assignments.  If you have a special schedule for endings (or leave, by the way) you'll probably want to include a WHERE clause in the main query does not display dates after the employee left (or when the employee was on leave).

  • XML data in the table using sql/plsql

    Hi experts,

    Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.

    Could someone please guide me if you have a sample code file and xml.

    <? XML version = "1.0" encoding = "UTF-8"? >

    < generation_date > <! [CDATA [17/11/2015]] > < / generation_date >

    < generated_by > <! [CDATA [Admin Admin]] > < / generated_by >

    < year > <! [CDATA [2015]] > < / year >

    < month > <! [CDATA [01]] > < / month >

    < author >

    < author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >

    < author_email > <! [CDATA [[email protected]]] > < / author_email >

    < author_data_01 > <! [CDATA []] > < / author_data_01 >

    < author_data_02 > <! [CDATA []] > < / author_data_02 >

    < items >

    < article_item >

    < article_id > <! [CDATA [123456]] > < / article_id >

    < publication > <! [CDATA [Al Bayan]] > < / publication >

    < section > <! [CDATA [Local]] > < / section >

    < issue_date > <! [CDATA [11/11/2015]] > < / issue_date >

    < page > <! [CDATA [2]] > < / print this page >

    < article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >

    < original_price > <! [CDATA [200]] > < / original_price >

    < original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >

    < price > <! [CDATA [250]] > < / price >

    < price_currency > <! [CDATA [DEA]] > < / price_currency >

    < / article_item >

    < / articles >

    < total_amount > <! [CDATA [250]] > < / total_amount >

    < total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >

    < / author >

    < / xml >

    Thanks in advance,

    Suman

    XMLTABLE using...

    SQL > ed
    A written file afiedt.buf

    1 with t (xml) as (select xmltype ('))
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [[12 [email protected]]] >
    13
    14
    15
    16
    17
    18
    19


    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33 ") of the double)"
    34-

    35 end of sample data
    36-
    37 - assumptions:
    (38 - a) XML may have several tags
    (39 - b) each may contain more
    40-
    41 select x.gen_by, x.gen_date, x.mn, x.yr
    42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2

    43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
    44 t
    45, xmltable ('/ authxml')
    from $ 46 t.xml
    path of 47 columns gen_date varchar2 (10) '. / generation_date'
    48, path of varchar2 (15) of gen_by '. / generated_by'
    49, path of varchar2 (4) year '. "/ year"
    50 varchar2 (2) mn road '. "/ month"
    51, path of xmltype authors '.'
    52                 ) x
    53, xmltable ('/ authxml/authors ')
    from $ 54 x.authors
    author of 55 path of varchar2 columns (15) '. / author'
    56, path of varchar2 (10) of auth_fn '. / author_firstname'
    57, path of varchar2 (10) of auth_ln '. / author_lastname'
    58 road of VARCHAR2 (3) auth_cnt '. / author_country'
    59 road of varchar2 (20) of auth_em '. / author_email'
    60 road of varchar2 (5) of auth_d1 '. / author_data_01'
    61, path of varchar2 (5) of auth_d2 '. / author_data_02'
    62, path of xmltype articles '. / Articles'
    63                 ) y
    64, xmltable ('/ Articles/article_item ')
    from $ 65 y.articles
    path id 66 number columns '. / article_id'
    67, path of varchar2 (10) pub '. ' / publication.
    68 road of varchar2 (10) dry '. / section'
    69, path of varchar2 (10) of iss_dt '. / issue_date'
    70 road of VARCHAR2 (3) pg '. "/ print this page"
    71, path of varchar2 (20) of art_ttl '. / article_title'
    72, path of varchar2 (5) of num_wrds '. / number_of_words'
    73, path of varchar2 (5) of oprice '. / original_price'
    74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
    75, path of varchar2 (5) price '. "/ price"
    76, path of VARCHAR2 (3) curr '. / price_currency'
    77*                ) z
    SQL > /.

    GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
    ---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
    17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title.   165 200 AED AED 250

    Of course, you'll want to change the types of data, etc. as needed.

    I assumed that the XML can contain several "" sections and that each section can contain several entries.

    Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself section of the XMLTABLE with alias 'z' for each of the article_item.

    CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)

  • Question to load data using sql loader in staging table, and then in the main tables!

    Hello

    I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.

    I have develop a shell script to load the data and it works fine except one thing.

    Here are the details of a data to re-create the problem.

    Staging of the structure of the table in which data will be filled using sql loader

    create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));

    create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));

    create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));

    DATA in the csv file-

    for stg_cmts_data-

    cmts_map_03092015_1.csv

    WNLB-CMTS-01-1. 10.15.0.1

    WNLB-CMTS-02-2 | 10.15.16.1

    WNLB-CMTS-03-3. 10.15.48.1

    WNLB-CMTS-04-4. 10.15.80.1

    WNLB-CMTS-05-5. 10.15.96.1

    for stg_dhcp_data-

    dhcp_map_03092015_1.csv

    DHCP-1-1-1. 10.25.23.10, 25.26.14.01

    DHCP-1-1-2. 56.25.111.25, 100.25.2.01

    DHCP-1-1-3. 25.255.3.01, 89.20.147.258

    DHCP-1-1-4. 10.25.26.36, 200.32.58.69

    DHCP-1-1-5 | 80.25.47.369, 60.258.14.10

    for stg_link_data

    cmts_dhcp_link_map_0309151623_1.csv

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5

    DHCP-1-1-3. WNLB-CMTS-01-1

    DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3

    DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7

    WNLB-DHCP-1-13 | WNLB-CMTS-02-2

    Now, after loading these data in the staging of table I have to fill the main database table

    create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));

    create table link (link_nm varchar2 (50));

    SQL scripts that I created to load data is like.

    coil load_cmts.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_cmts IS SELECT *.

    OF stg_cmts_data;

    TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;

    l_stg_cmts t_stg_cmts;

    l_cmts_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_cmts.

    Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;

    BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST

    LOOP

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;

    IF l_cmts_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_cmts (i) .cmts_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_cmts EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for dhcp


    coil load_dhcp.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_dhcp IS SELECT *.

    OF stg_dhcp_data;

    TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;

    l_stg_dhcp t_stg_dhcp;

    l_dhcp_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_dhcp.

    Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;

    BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST

    LOOP

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;

    IF l_dhcp_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_dhcp (i) .dhcp_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_dhcp EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for link -.

    coil load_link.log

    Set serveroutput on

    DECLARE

    l_cmts_1 VARCHAR2 (4000 CHAR);

    l_cmts_add VARCHAR2 (200 CHAR);

    l_dhcp_cnt NUMBER;

    l_cmts_cnt NUMBER;

    l_link_cnt NUMBER;

    l_add_link_nm VARCHAR2 (200 CHAR);

    BEGIN

    FOR (IN) r

    SELECT dhcp_token, cmts_to_add | ',' cmts_add

    OF stg_link_data

    )

    LOOP

    l_cmts_1: = r.cmts_add;

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = r.dhcp_token;

    IF l_dhcp_cnt = 0 THEN

    DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);

    ON THE OTHER

    While l_cmts_add IS NOT NULL

    LOOP

    l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = TRIM (l_cmts_add);

    SELECT COUNT (1)

    IN l_link_cnt

    LINK

    WHERE link_nm = l_add_link_nm;

    IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN

    INSERT INTO link (link_nm)

    VALUES (l_add_link_nm);

    DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;

    ELSIF l_link_cnt > 0 THEN

    DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);

    ELSIF l_cmts_cnt = 0 then

    DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);

    END IF;

    l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    END LOOP;

    END IF;

    END LOOP;

    COMMIT;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    control files -

    DOWNLOAD THE DATA

    INFILE 'cmts_data.csv '.

    ADD

    IN THE STG_CMTS_DATA TABLE

    When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')

    and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:cmts_token))' cmts_token,

    cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "

    for dhcp.


    DOWNLOAD THE DATA

    INFILE 'dhcp_data.csv '.

    ADD

    IN THE STG_DHCP_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "

    for link -.

    DOWNLOAD THE DATA

    INFILE 'link_data.csv '.

    ADD

    IN THE STG_LINK_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""

    SHELL SCRIPT-

    If [!-d / log]

    then

    Mkdir log

    FI

    If [!-d / finished]

    then

    mkdir makes

    FI

    If [!-d / bad]

    then

    bad mkdir

    FI

    nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    nohup time username/password@SID @load_cmts.sql

    nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_dhcp.sql

    nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_link.sql

    MV *.log. / log

    If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.

    Now that we can here multiple CMTS are associated with unique DHCP.

    So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.

    for example

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2

    Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.

    same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).

    But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.

    Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.

    I use COMMIT in my script also but it only does not help me.

    Run these scripts in your machine let me know if you also get the same behavior I get.

    and please give me a solution I tried many thing from yesterday, but it's always the same.

    It is the table of link log

    link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2

    link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3
    link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3

    link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2
    link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7

    Device not found: wnlb-dhcp-1-13

    IF NEED MORE INFORMATION PLEASE LET ME KNOW

    Thank you

    I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.

    It was the dos2unix error!

    Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)

  • date of end of month in SPR

    We must show the date of end of month for a given date in a table.
    The date is March 25, 2008 ", then output should give me 31 March 2008".
    I want to create a new column derived like this in the RPD.
    I think that variables can not help me out here, because we need to have the date of end of month for each value that the date column will hold.
    Please let me know how can achieve us.

    I haven't played a lot with the expression of OBIEE constructor functions but the technique below should work, you can use standard date functions:

    (1) take the month and year of your date column (for example for today, it will be 10/2008) convert it to a string.
    (2) date data type concatenate 01 to the string of the previous step and convert the entire expression. Now you have the first date of the month of your column in a date format.
    ((3) on the date to 2) add 1 month and 1 day to remove and you get the last day of the month for your selected date.

    Should work in OBIEE too.

  • AT100 - impossible to get my calendar to store the dates of the annual events

    Hello.

    Cannot get my calendar to store the dates of the annual events birthdays for example.
    Option gives (annual 27 July 2012), but would it be fair (27 July each year). No way to remove year so presumably won't wait that 2012 will come along! All the other choices for weekly and monthly do not specify the year.

    Annual option should I think be the same. Tried to enter next year, but comes with (year July 27, 2013) so it looks that have to enter every year which is a pain. Someone at - it ideas.

    It's my first post he hopes in the right place.

    Thank you

    Hello

    Why you n t try another Android app like for example calendar of birthday or anniversary Assistant

  • Get the number of month, week and day between 2 dates

    Hi all

    Is it possible to display the number of months, weeks and days between 2 dates? by using only the SQL or PL/SQL...

    Entry:
    Date: October 1, 2010
    Date: October 19, 2010

    I want output like below (assuming starts the week from Monday to Sunday in oracle).

    October 1, 2010-(since it's in the middle of the week)
    October 2, 2010-(since it's in the middle of the week)
    October 3, 2010-(since it's in the middle of the week)
    40. (4 Oct-10 Oct falls into the 40th week of the year)
    41. (11 Oct-17 Oct falls into the 41st week of the year)
    October 18, 2010-(since it's in the middle of the week)
    October 19, 2010-(since it's in the middle of the week)


    Note: If there is a month between the date, the number of the month should be displayed.
    End of the month, the remaining date included with a full week, then the week of the year number should
    displayed. After posting the week, remaining dates should be displayed as it is...


    Appreciate your help...



    Thank you.
    Fox.

    You mean something like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH t AS (select date '2010-09-27' as fdate, date '2010-11-21' as tdate from dual)
      2  --
      3  -- END OF TEST DATA
      4  --
      5  select dt2
      6  from (
      7        select dt,
      8               case when days_of_mn = days_in_month then 'Whole: '||to_char(dt,'Month')
      9                    when days_of_wk = 7 then 'Week: '||to_char(dt,'fmWW')
     10               else to_char(dt, 'DD-fmMonth-YYYY')
     11               end as dt2
     12              ,row_number() over (partition by
     13                 case when days_of_mn = days_in_month then to_char(dt,'Month')
     14                                  when days_of_wk = 7 then 'Week: '||to_char(dt,'fmWW')
     15                 else to_char(dt, 'DD-fmMonth-YYYY')
     16                 end order by dt) as rn
     17        from (
     18              select dt, wk, mn, days_in_month
     19                    ,count(*) over (partition by wk) as days_of_wk
     20                    ,count(*) over (partition by mn) as days_of_mn
     21              from (
     22                    select fdate+rownum-1 as dt
     23                          ,to_number(to_char(fdate+rownum-1,'fmWW')) as wk
     24                          ,to_number(to_char(fdate+rownum-1,'fmMM')) as mn
     25                          ,to_number(to_char(last_day(fdate+rownum-1),'fmDD')) as days_in_month
     26                    from t
     27                          connect by rownum <= tdate-fdate+1
     28                   )
     29             )
     30        ) x
     31  where rn = 1
     32* order by dt
    SQL> /
    
    DT2
    -----------------
    27-September-2010
    28-September-2010
    29-September-2010
    30-September-2010
    Whole: October
    Week: 44
    Week: 45
    Week: 46
    19-November-2010
    20-November-2010
    21-November-2010
    
    11 rows selected.
    
    SQL>
    

Maybe you are looking for