Splitting one row to multiple rows

Hi
I am new to Oracle so please pardon me if any mistakes
I have a requirement where in sorurce table table 1 the data is as below
INPUT.......
col1 col2 col3 Fromdate Todate
xxx yyy 200 2010-01-01 2010-03-01
OUTPUt.....should be as follows
Col1 Col2 Col3 Month
xxx yyy 20 jan
xxx yyy 20 feb
xxx yyy 20 mar
How can we acheive this?
Edited by: user13103678 on May 10, 2010 11:23 PM

Hi,
Please post your question in the "SQL and PL/SQL" forum for a better/faster response.
SQL and PL/SQL
PL/SQL
Thanks,
Hussein

Similar Messages

  • Split single row in multiple rows based on date range

    I need sql script that can split single row in multiple rows based on start date and end date column in table.
    Thank you

    I agree to your suggestion of having a dates table permanently in the database. Thats how we also do for most of our projects as well
    But in most projects the ownership  of table creation etc lies with the client as they will be the DBAs and will be design approval authorities. What I've seen is the fact that though
    many of them are in favour of having calendar table they dont generally prefer having a permanent table for numbers in the db. The best that they would agree is for creating a UDF which will have
    tally table functionality built into it based on a number range and can be used in cases where we need to multiply records as above.
    Wherever we have the freedom of doing design then I would also prefer creating it as a permanent table with required indexes as you suggested.
    >> many of them are in favour of having calendar table they dont generally prefer having a permanent table
    Those people do not understand about database and are not DBAs :-)
    It is our job to tell them what is right or wrong.
    ** This is a real story! I had a client several years back, who was the CEO of a software company.
    He use the query:
    select * from table_name
    In order to get the last ID!
    The table_name was actually a view that took data from several tables, and the main table that he wanted to get the ID included several string columns, with lot of data!
    he actually pulled all this data to the application, just to get the lat ID in a specific table!
    It is our job as Consultants or DBAs to fix's his misunderstanding :-)
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

  • Split single row into multiple rows containing time periods

    Hi,
    I have a table with rows like this:
    id, intime, outtime
    1, 2010-01-01 00:10, 2010-01-3 20:00
    I would like to split this row into multiple rows, 1 for each 24hr period in the record.
    i.e. The above should translate into:
    id, starttime, endtime, period
    1, 2010-01-01 00:10, 2010-01-02 00:10, 1
    1, 2010-01-02 00:10, 2010-01-03 00:10, 2
    1, 2010-01-03 00:10, 2010-01-03 20:00, 3
    The first starttime should be the intime and the last endtime should be the outtime.
    Is there a way to do this without hard-coding the 24hr periods?
    Thanks,
    Dan Scott
    http://danieljamesscott.org

    Thanks for all the feedback, Dan.
    It appears that the respective solutions provided will give you: a) different resultsets and b) different performance.
    Regarding your 'truly desired resultset' you haven't answered all questions from my previous post (there are differences in the provided examples), but anyway:
    I found that using CEIL or ROUND makes quite a difference, using my 'simple 3 record testset' (30 records vs. 66 records got initially returned, that's less than half of the original). That's quite a difference. However, I must call it a day (since it's almost midnight) for now, so there's room for more optimizement and I haven't thoroughly tested.
    But this might hopefully make a difference performancewise when compared to my previous 'dreaded example':
    SQL> drop table t;
    Table dropped.
    SQL> create table  t as
      2  select 1 id, to_date('2010-01-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-01-03 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      3  select 2 id, to_date('2010-02-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-02-05 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      4  select 3 id, to_date('2010-03-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-03-03 00:10', 'yyyy-mm-dd hh24:mi') outtime from dual;
    Table created.
    SQL> select id
      2  ,      max(intime)+level-1 starttime
      3  ,      case
      4           when level = to_char(max(t.outtime), 'dd')
      5           then max(t.outtime)
      6           else max(t.intime)+level
      7         end outtime
      8  ,      level period      
      9  from   t
    10  connect by level <= round(outtime-intime)
    11  group by id, level
    12  order by 1,2;
            ID STARTTIME           OUTTIME                 PERIOD
             1 01-01-2010 00:10:00 02-01-2010 00:10:00          1
             1 02-01-2010 00:10:00 03-01-2010 00:10:00          2
             1 03-01-2010 00:10:00 03-01-2010 20:00:00          3
             2 01-02-2010 00:10:00 02-02-2010 00:10:00          1
             2 02-02-2010 00:10:00 03-02-2010 00:10:00          2
             2 03-02-2010 00:10:00 04-02-2010 00:10:00          3
             2 04-02-2010 00:10:00 05-02-2010 00:10:00          4
             2 05-02-2010 00:10:00 05-02-2010 20:00:00          5
             3 01-03-2010 00:10:00 02-03-2010 00:10:00          1
             3 02-03-2010 00:10:00 03-03-2010 00:10:00          2
    10 rows selected.
    SQL> By the way: I'm assuming you're on 10g, is that correct?
    Can you give us some information regarding the indexes present on your table?

  • How can i select some row from multiple row in the same group of data

    I want to select some row from multiple row in the same group of data.
    ColumnA        
    Column B
    1                  OK
    1                   NG
    2                   NG
    2                          NG
    3                          OK
    3                          OK
    I want the row of group of
    ColumnA if  ColumnB contain even 'NG'
    row , select only one row which  Column B = 'NG'
    the result i want = 
    ColumnA         Column B
    1                         NG
    2                   NG
    3                          OK
    Thank you

    That's some awful explanation, but I think this is what you were driving at:
    DECLARE @forumTable TABLE (a INT, b CHAR(2))
    INSERT INTO @forumTable (a, b)
    VALUES
    (1, 'OK'),(1, 'NG'),
    (2, 'NG'),(2, 'NG'),
    (3, 'OK'),(3, 'OK')
    SELECT f.a, MIN(COALESCE(f2.b,f.b)) AS b
    FROM @forumTable f
    LEFT OUTER JOIN @forumTable f2
    ON f.a = f2.a
    AND f.b <> f2.b
    GROUP BY f.a

  • Rows to multiple rows

    Hi Tom,
    Table having huge volume of data and want to split single row to multiple rows.I mean split based on acc1 and id1
    ex:
    SELECT acc1,id1,acc2, id2 FROM TGDW_ACCT
    acc1 id1 acc2 id2
    6000161114 002 6000251684 001
    6000161115 001 6000251687 004
    Expecting o/p
    acc1 id1
    6000161114 002
    6000251684 001
    6000161115 001
    6000251687 004
    Thanks and Regards,
    MR

    Hi,
    drop table DENEME2;
    create table DENEME2 (acc1 number,id1 VARCHAR2(10),acc2 number,id2 VARCHAR2(10));
    BEGIN
    INSERT INTO DENEME2 VALUES ('6000161114','002','6000251684','001');
    INSERT INTO DENEME2 VALUES ('6000161115','001','6000251687','004');
    COMMIT;
    END;
    UYGULAMA@XE> SELECT ACC1,ID1 FROM DENEME2
    2 UNION ALL
    3 SELECT ACC2,ID2 FROM DENEME2;
    ACC1 ID1
    6000161114 002
    6000161115 001
    6000251684 001
    6000251687 004

  • Single row to multiple row

    Hi All,
    I need a help in a query to convert a row to multiple row.
    I have two tables
    TableA
    ID1 attribute1_Name attribute1_code
    ID1 attribute2_Name attribute2_code
    ID2 attribute1_Name attribute1_code
    ID2 attribute2_Name attribute2_code
    ID2 attribute3_Name attribute3_code
    ID4 attribute1_Name attribute1_code
    ID4 attribute2_Name attribute2_code
    ID4 attribute3_Name attribute3_code
    ID4 attribute4_Name attribute4_code
    attribute name and attribute code can vary 1 to n for different id
    let's one ID has maximum no of codes 20 , then TableB will have columns like (EMP ID attribuute_code1 attribuute_code2 .... attribuute_code20)
    in TableB all the columns named attribuute_code1 ..attribuute_code20 will have value for those attribute
    TableB ( )
    Column EMP ID attribuute_code1 attribuute_code2 attribuute_code3 attribuute_code4
    EMP1 ID1 attribute1_value attribute2_value null null
    EMP2 ID1 attribute1_value attribute2_value attribute3_value null
    EMP3 ID2 attribute1_value attribute2_value attribute3_value attribute4_value
    EMP and ID is composite p.k
    My resulting table should have
    EMP1 ID1 attribute1_value
    EMP1 ID1 attribute2_value
    EMP2 ID1 attribute1_value
    EMP2 ID1 attribute2_value
    EMP2 ID1 attribute3_value
    EMP3 ID2 attribute1_value
    EMP3 ID2 attribute2_value
    EMP3 ID2 attribute3_value
    EMP3 ID2 attribute4_value
    Thanks in advance ...

    hi ,
    i am using oracle 10g
    i tried the way u said , but i'm getting few uncecessary rows .
    here i am giving u the example script
    for table_A
    create table TABLE_A
    ID VARCHAR2(50),
    ATTRIBUTE_NAME VARCHAR2(50),
    ATTRIBUTE_CODE VARCHAR2(50)
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID1', 'attribute1_Name', 'attribute1_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID1', 'attribute2_Name', 'attribute2_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID2', 'attribute1_Name', 'attribute1_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID2', 'attribute2_Name', 'attribute2_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID2', 'attribute3_Name', 'attribute3_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID4', 'attribute1_Name', 'attribute1_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID4', 'attribute2_Name', 'attribute2_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID4', 'attribute3_Name', 'attribute3_code');
    insert into TABLE_A (ID, ATTRIBUTE_NAME, ATTRIBUTE_CODE)
    values ('ID4', 'attribute4_Name', 'attribute4_code');
    for table_b
    create table TABLE_B
    EMP_NAME VARCHAR2(40),
    ID VARCHAR2(50),
    ATTRIBUTE1_VALUE NUMBER,
    ATTRIBUTE2_VALUE NUMBER,
    ATTRIBUTE3_VALUE NUMBER,
    ATTRIBUTE4_VALUE NUMBER
    insert into TABLE_B (EMP_NAME, ID, ATTRIBUTE1_VALUE, ATTRIBUTE2_VALUE, ATTRIBUTE3_VALUE, ATTRIBUTE4_VALUE)
    values ('EMP1', 'ID1', 10, 20, null, null);
    insert into TABLE_B (EMP_NAME, ID, ATTRIBUTE1_VALUE, ATTRIBUTE2_VALUE, ATTRIBUTE3_VALUE, ATTRIBUTE4_VALUE)
    values ('EMP2', 'ID1', 30, 40, 50, null);
    insert into TABLE_B (EMP_NAME, ID, ATTRIBUTE1_VALUE, ATTRIBUTE2_VALUE, ATTRIBUTE3_VALUE, ATTRIBUTE4_VALUE)
    values ('EMP3', 'ID2', 60, 70, 80, 90);
    resulting table data shud come like: let it be table_c
    create table TABLE_C
    EMP_NAME VARCHAR2(50),
    ID VARCHAR2(50),
    ATTRIBUTE_CODE VARCHAR2(50),
    ATTRIBUTE_VALUE NUMBER
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP1', 'ID1', 'attribute1_code', 10);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP1', 'ID1', 'attribute2_code', 20);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP2', 'ID1', 'attribute1_code', 30);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP2', 'ID1', 'attribute2_code', 40);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP2', 'ID1', 'attribute3_code', 50);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP3', 'ID2', 'attribute1_code', 60);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP3', 'ID2', 'attribute2_code', 70);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP3', 'ID2', 'attribute3_code', 80);
    insert into TABLE_C (EMP_NAME, ID, ATTRIBUTE_CODE, ATTRIBUTE_VALUE)
    values ('EMP3', 'ID2', 'attribute4_code', 90);
    thanx

  • I need to divide selected row into multiple rows when i navigate  ADF 11g

    Hi
    I'm using jdeveloper 11.1.1.2.0 with ADF 11g.
    I need to divide selected row into multiple rows when i navigate to other page . Scenario - in first page i'm displaying some records with columns like empno , empstatus , empworkdepts ,curdepts
    Here empworkdepts gives the numeric number like no of departments work shifts 3 or 4 or 5. when i select any particular employee and fire next button to navigate next page.I have to divide the selected employee with same information into multiple times based on the empworkdepts value.
    empno empstatus empworkdepts curdept
    001 eds 2 TS
    002 hr 1 FO
    003 eds 4 TS
    *004 eds 3 TS*
    now i selected employee 004 , when i navigate to next page.
    Empno EmpStatus EmpWorkDepts CurDept
    004 eds 3 TS
    004 eds 3 TS
    004 eds 3 TS
    i did with java code in bean .but not stable .
    any help............
    thanks advance.............
    Edited by: user9010551 on May 5, 2010 10:48 PM
    Edited by: user9010551 on May 10, 2010 11:31 PM

    user9086775 wrote:
    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product     Sub Product          Name    Age
    New Car    Nissan                   Tom        49
    New Car    Nissan                   Jack         36
    Old Car      Audi                     Sam         24
    Old Car      Jaguar                  Pint          26
    Old Car      Audi                     Smith       41
    I need to be able to fetch the above data in the below fashion
    Product     Sub Product          Name    Age
    New Car
    Nissan
    Tom        49
    Jack        36
    Old Car     
    Audi            
    Sam        24
    Smith      41
    Jaguar                   Pint         26Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!You should be doing this in the client on not in the DB. Use the reporting tool that you use to do this.
    For example if you are in SQL Plus you can use the BREAK command.

  • Urgent: How to break 1 Row into Multiple Rows

    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product Sub Product Name Age
    New Car Nissan Tom 49
    New Car Nissan Jack 36
    Old Car Audi Sam 24
    Old Car Jaguar Pint 26
    Old Car Audi Smith 41
    I need to be able to fetch the above data in the below fashion
    Product Sub Product Name Age
    New Car
    Nissan
    Tom 49
    Jack 36
    Old Car
    Audi
    Sam 24
    Smith 41
    Jaguar Pint 26
    Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!

    user9086775 wrote:
    Hi Experts,
    I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
    Requirment:
    This is a sample set record in a table
    Product     Sub Product          Name    Age
    New Car    Nissan                   Tom        49
    New Car    Nissan                   Jack         36
    Old Car      Audi                     Sam         24
    Old Car      Jaguar                  Pint          26
    Old Car      Audi                     Smith       41
    I need to be able to fetch the above data in the below fashion
    Product     Sub Product          Name    Age
    New Car
    Nissan
    Tom        49
    Jack        36
    Old Car     
    Audi            
    Sam        24
    Smith      41
    Jaguar                   Pint         26Please help with ideas as to how can i achive the above without using PLSQL.
    Thanks in advance!You should be doing this in the client on not in the DB. Use the reporting tool that you use to do this.
    For example if you are in SQL Plus you can use the BREAK command.

  • How do I divide a list in one cell into multiple rows?

    I have copied lists of data from a website - some lists pasted as I want them (in individual rows), but others pasted the list in one row.  Is there an easy way to split a list in a single cell into multiple cells so ultimately I can sort all the rows?  I've tried "split the selected cells into rows" in the inspector, but it's not working... seems like it's creating another column instead (?).  Any help would be amazing.

    K,
    I find that Pages has the friendliest Find and Replace dialog, so when I need to swap around the delimiters I go straight to Pages and do the fixes there. Replace whatever is there between columns in the original content with Tab characters and replace whatever is there now for delimiting the rows with the Return character. Since it's sometimes difficult to tell what has been used, just copy it from the content and Paste into the Find field. Choose the Tab or Return character from the Replace drop down menu.
    When you have it all fixed up, then paste into Numbers.
    Jerry

  • Easy Question: How to split concatenated string into multiple rows?

    Hi folks,
    this might be an easy question.
    How can I split a concatenated string into multiple rows using SQL query?
    INPUT:
    select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
    Expected output:
    data
    AAA
    BBB
    CCC
    DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
    Thanks,
    Tomas

    Here is the SUBSTR/INSTR version of the solution:
    SQL> WITH test_data AS
      2  (
      3          SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
      4  )
      5  SELECT  SUBSTR
      6          (
      7                  DATA
      8          ,       INSTR
      9                  (
    10                          DATA
    11                  ,       ','
    12                  ,       1
    13                  ,       LEVEL
    14                  ) + 1
    15          ,       INSTR
    16                  (
    17                          DATA
    18                  ,       ','
    19                  ,       1
    20                  ,       LEVEL + 1
    21                  ) -
    22                  INSTR
    23                  (
    24                          DATA
    25                  ,       ','
    26                  ,       1
    27                  ,       LEVEL
    28                  ) - 1
    29          )       AS NEW_STRING
    30  FROM    test_data
    31  CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
    32  /
    NEW_STRING
    AAA
    BBB
    CC
    DDDD

  • Splitting a message with multiple rows from the JDBC Adapter

    Hi,
    I'd like to split the resultset message with multiple row elements and process each row separately..
    Does someone have this experience?
    Thanx, Peter

    Hi Chandrasekhar,
    I tried to follow your advise, but I'm not able to complete the process correctly.
    Let me explain my process:
    First - output from the JDBC adapter goes into the first receive step. Of course, there are multiple ROW elements. (Should be marked the ingoing message marked in the container as Multiline??)
    The next should be the transformation:
    format of the source message is like
    <message>
      <row>
        <column>w</column>
      </row>
      <row>
        <column>w</column>
      </row>
    </message>
    In the message I have the ROW element as 0..unbounded
    and <column> element exactly 1
    This message should be mapped to multiple messages of the format:
    <message>
      <value>w</value>
    </message>
    How should be the mapping be done?
    Is it N:1 or 1:N (because in another thread there was an 1:N mapping advised)
    Then (as you say) should follow the Block step:
    Which message (container element) should be marked as Multiline? And what does it mean: Current Message?
    Can you give me some advise, when and how to use the multiline mark?
    Thanx a lot, Peter

  • SSIS + split 1 row in multiple rows based on multiple columns

    Hi all,
    I have a flat file 
    Shop ID        Check 1        Check 2            Check 3
    500 OK
    OK NOK
    I want to transform this to staging as 3 rows
    Shop ID       Check number 
    Result
    500 1
    OK
    500 2
    OK
    500 3
    NOK
    Anyone can tell me how to tackle this?

    I basically have a table that has the columns I specified
    Shop Check 1
    Check 2 Check 3
    500 OK
    OK NOK
    I now want to actually have them loaded in another table where I have multiple rows for each shop.
    Shop Check
    Result
    500
    1 ok
    500 2
    ok
    500 3
    nok
    So basically I want to go from a column view to a row view. Is this possible?
    In other words, I do see multiple rows for each shop ID which is awesome! But I would like to have instead of the result that number of the check. (1,2,3) with the result next to it :)
    500  OK
    500 OK
    500 NOK

  • Table row with multiple row

    Hi All,
    I am using NWDS 2004
    I want to have a table with multiple rows in a row.
    Can any one help ?
    Thanks

    hi Akhilesh,
    Use tree table for your requirement.
    [Tree Table Tutorial|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/de59f7c2-0401-0010-f08d-8659cef543ce]
    Hope this helps!
    Monalisa

  • Single Update command to update multiple rows with multiple rows

    Hi Gurus!
    Can I update table A with a result set of table b (multiple rows returns) where a.c1 = b.c1
    regards,
    SH

    As Joel mentioned this update will update all rows in a table based on another one:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    Also, any rows that don't match the select criteria will get updated to null. This could be very bad depending on what you want to do.
    To update a subset of tableA with data from tableB:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    where exists (select 1 from tableB where tableA.ID = tableB.ID)

  • During import, how to auto split one project into multiple albums based on date?

    I believe I've done enough aperture reserach to get all my terminology right, so here goes...
    I've created a file structure within the aperture inspector the the tune of: 
    Year [folder], Type of event (Occasion, special occasion, holiday, vacation) [folder], Project (Wedding), Album (i.e. Day 1, Day 2 or Pre wedding week, event, honeymoon).
    I also have entire months with 7 or 8 pictures each day, that are of the same type/project (random dog pictures) but are distinctly different days (albums - day in park, in bed at night, watching movie). 
    My question is, can I import one project with multiple albums already created based on the date they're taken.  As I can see it, all I can do is split individual projects automatically by date.  But what if one project is over one month, but has multiple distinct days that would be ideal for albums?  One more example.  We did a trip to San Fran.  One day was touring the city, one day was a concert, another day was touring the city.  All one project, but 3 different albums (in my mind).  I had to import as one project, then separately go in and make albums.  I would like that done automatically.
    My suspicion is that I can not natively do this within aperture, and that I would need something called an "applescript."  I haven't done any reserach into that area, so if that's the case and you know where I can find a script that would do this, I'd appreciate the help. 
    Sorry for the wordiness, just wanted to be clear.  Thanks for any and all help!

    Hi,
    You need to create a new requirement in tcode VOFM for that, together with your ABAP consultant. This requirement will be used in copy contol.
    http://saptechsolutions.com/pdf/VOFMCopyRequirementRoutines.pdf
    MdZ

  • 1 row into multiple rows

    I have a table time_entries
    create table time_entries
    (employee_id integer,
    start_date date,
    end_date date,
    CONSTRAINT pk_time_entries PRIMARY KEY (employee_id, start_date))Suppose I have one row in this table (dates in yyyy-mm-dd format):
    employee_id, start_date, end_date
    1, 2012-08-27, 2012-09-02
    As you can see the difference between the dates is 7 days. I want to write a query so that each day has its own row, i.e. I want to write a query which translates the above 1 row into 7 rows. This is the result set I want:
    employee_id, start_date, end_date
    1, 2012-08-27, 2012-08-27
    1, 2012-08-28, 2012-08-28
    1, 2012-08-29, 2012-08-29
    1, 2012-08-30, 2012-08-30
    1, 2012-08-31, 2012-08-31
    1, 2012-09-01, 2012-09-01
    1, 2012-09-02, 2012-09-02
    Is it possible to do it in one select statement?
    Edited by: srhcan on Aug 17, 2012 4:26 PM
    Edited by: srhcan on Aug 17, 2012 4:26 PM

    WITH t
         AS (SELECT 1 id,
                    TO_DATE ('2012-08-27', 'yyyy-mm-dd') start_date,
                    TO_DATE ('2012-09-02', 'yyyy-mm-dd') end_date
               FROM DUAL
             UNION ALL
             SELECT 2 id,
                    TO_DATE ('2012-10-27', 'yyyy-mm-dd') start_date,
                    TO_DATE ('2012-11-02', 'yyyy-mm-dd') end_date
               FROM DUAL)
    SELECT id, start_date, end_date
      FROM t
    MODEL
       PARTITION BY (id)
       DIMENSION BY (0 d)
       MEASURES (start_date, end_date, end_date stop)
       RULES
          ITERATE (10000) UNTIL start_date[ITERATION_NUMBER] = stop[0]
          (start_date [ITERATION_NUMBER] = start_date[0] + ITERATION_NUMBER,
          end_date [ITERATION_NUMBER] = start_date[0] + ITERATION_NUMBER)
    ID     START_DATE     END_DATE
    1     8/27/2012     8/27/2012
    1     8/28/2012     8/28/2012
    1     8/29/2012     8/29/2012
    1     8/30/2012     8/30/2012
    1     8/31/2012     8/31/2012
    1     9/1/2012     9/1/2012
    1     9/2/2012     9/2/2012
    2     10/27/2012     10/27/2012
    2     10/28/2012     10/28/2012
    2     10/29/2012     10/29/2012
    2     10/30/2012     10/30/2012
    2     10/31/2012     10/31/2012
    2     11/1/2012     11/1/2012
    2     11/2/2012     11/2/2012

Maybe you are looking for

  • Using Non cumulative key figure in Real time cube

    Hi gurus, I have used non cumulative key figure in a real time cube and when i tried to enter some data using RSINPUT ,it is giving an error and the data is not getting saved. Can anyone please tell me how to use the Non cumulative key figure in the

  • Using Numbers, I need to time-stamp each line in a table for when it was entered

    I need to time-stamp each line in a table for when it was entered. I have a formula which is "=IF(F18="","",NOW())" it gives me the answer I want, but every time I edit any data in the formula is recalculates the date/time to reflect the most recent

  • So tired of iTunes & Podcasts, recommendations?

    latest iTunes, OSX & IOS.  iTunes corrupted a week ago...again.  I completely rebuilt it on another, less used HD.  It's corrupted again now.  Freezes when I try to download podcast updates, claims 100% of my CPU, and runs the fan on high.  No other

  • Can we create range variable for Query Key Date

    Hello Gurus, Can we create a range variable for Query Key Date ? when I tried to give a range of values for Query Key Date, I am unable to find Range Values option. I found only Single Values. so, Please let me know if we can use Range variables for

  • Mac user in Windows instuttion needs help

    I am being denied IMAP for my .mac mail by the syst. adm. and firewall provider. I think they are blowing me off but my tech understanding on this matter is lacking in order to defend my case. Please read the email exchange below and provide a counte