Split one row into multiple columns

Hi,
Data in one CLOB column in a table storing with delimiter, ##~~##. Ex. ##~~##abc##~~##defgh##~~##ijklm##~~##nopqr (data starts with delimiter). Please help me to split the data into multiple rows like below and it should be in the same order.
abc
defgh
ijklm
nopqr
I am using Oracle 11g.
Thanks.

Thanks Hoek for your response. Before posting my question in the forum, I tried similar query. It is working with one character as delimiter.
with test as (select 'ABC,DEF,GHI,JKL,MNO' str from dual )
select regexp_substr (str, '[^,]+', 1, rownum) split
from test
connect by level <= length (regexp_replace (str, '[^,]+')) + 1;
Above query is giving correct result by fetching 5 rows. I have modified the query like below...
with test as (select 'ABC,,,DEF,,,GHI,,,JKL,,,MNO' str from dual )
select regexp_substr (str, '[^,,,]+', 1, rownum) split
from test
connect by level <= length (regexp_replace (str, '[^,,,]+')) + 1;
Above query resulting 13 rows and last 8 rows are nulls. Number of null rows are increasing, if I increase number of characters in delimiter. Could you please tell me how to avoid those null rows.
Thanks.

Similar Messages

  • One Row into multiple Column

    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    I am trying to get output following format
    ID_1    ID_2   ID_3  ID_4
    100     200    300   400
    1000    1200   1300  1400
    Each row in EmpId column will have only max. four values
    Thanks
    V

    One more method:
    CREATE TABLE #ids (empid VARCHAR(200))
    INSERT INTO #ids SELECT '100,200,300,400'
    INSERT INTO #ids SELECT '1100,1200,1300,1400'
    select * from #ids
    ;WITH
    L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
    L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
    L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
    L3 AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
    Numbers AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM L3)
    SELECT [1] AS Column1, [2] AS Column2, [3] AS Column3, [4] AS Column4
    FROM
    (SELECT rn,
    ROW_NUMBER() OVER (PARTITION by rn ORDER BY nums.n) AS PositionInList,
    LTRIM(RTRIM(SUBSTRING(valueTable.empid, nums.n,
    charindex(N',', valueTable.empid + N',', nums.n) - nums.n))) AS [Value]
    FROM Numbers AS nums INNER JOIN (Select row_number()over (Order by (Select NULL)) rn , Empid From #ids) AS valueTable ON nums.n <= CONVERT(int, LEN(valueTable.empid))
    AND SUBSTRING(N',' + valueTable.empid, n, 1) = N',') AS SourceTable
    PIVOT
    MAX([VALUE]) FOR PositionInList IN ([1], [2], [3], [4])
    ) AS Table2
    drop table #ids

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

  • Query to split one row to multiple based on date range

    Hi,
    I need to split single row into multple based on date range defined in a column, start_dt and end_dt
    I have a data
    ID      From date             End_dt                measure
    1        2013-12-01         2013-12-03            1
    1        2013-12-04         2013-12-06            2
    2        2013-12-01         2013-12-02            11
    3        2013-12-03         2013-12-04          22
    I required output as
    ID      Date                      measure
    1        2013-12-01              1
    1        2013-12-02              1
    1        2013-12-03              1
    1        2013-12-04              2
    1        2013-12-05              2
    1        2013-12-06              2
    2        2013-12-01             11
    2        2013-12-02             11
    3        2013-12-03             22
    3        2013-12-04            22
    Please provide me sq, query for the same
    Amit
    Please mark as answer if helpful
    http://fascinatingsql.wordpress.com/

    Have a calendar table for example and then probably using UNION ALL from date  and stat date JOIN the Calendar table
    SELECT ID,From date  FROM tbl
    union all
    SELECT ID,End_dt FROM tbl
    with tmp(plant_date) as
       select cast('20130101' as datetime)
       union all
       select plant_date + 1
         from tmp
        where plant_date < '20131231'
    select*
      from  tmp
    option (maxrecursion 0)
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Convert one row to multiple column dynamic in smartform

    i want to convert on row to multiple column in smartform.As number of column is not per define..Please suggest the way out in smartform

    I saw a post and working perfect. The link is given below.
    http://scn.sap.com/community/abap/blog/2013/10/06/the-case-of-dynamic-columns-in-smartform
    Thanks to Eitan.

  • 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

  • How to transpose rows into multiple columns using pivot table

    I have 1 row containing 12 columns with value "JAN", "FEB", "MAR", "J-1","F-1","M-1","J-2","F-2","M-2","J-3","F-3","M-3"
    I want to display as
    JAN J-1 F-1 M-1
    FEB J-2 F-2 M-2
    MAR J-3 F-3 M-3
    How do I achieve the above?

    Today you have only 3 months JAN, FEB, MAR. Is it always the same number of columns. What if there are more months added to this row?
    Is your data really coming from relational source or some sort of text file?
    There is a better way to do this in narrative view using HTML if your requirement is just to show them in multiple rows and do some calculations.
    Go to Narrative View;
    In prefix, use <html> <table>
    In 'Narrative' text box add something like this
    <tr> <td> @1 </td> <td> @4 </td> <td> @7 </td> </tr>
    <tr> <td> @2 </td> <td> @5 </td> <td> @8 </td> </tr>
    <tr> <td> @3 </td> <td> @6 </td> <td> @9 </td> </tr>
    In Suffix, use </table> </html>
    You can also add simple calculations like sum etc at the very bottom of these rows as grand totals.
    kris

  • Display rows into multiple columns

    I have a table in the following format:
    id value
    a1 0
    a2 0
    a3 0
    a4 0
    b1 0
    b2 0
    b3 0
    b4 0
    how do I go about displaying it into four columns in the following format:
    id1 value1 id2 value2
    a1 0 b1 0
    a2 0 b2 0
    a3 0 b3 0
    a4 0 b4 0

    Hi,
    789063 wrote:
    I got that error in toad. So now I am testing from command prompt. When you say "command prompt", do you mean SQL*Plus?
    Sorry, I don't know much about Toad. If Toad is returning 0 rows, and the same query is returning 8 rows in SQL*Plus, then I suspect you are not connecting to the same database or the same user. ASre you sure you're running the exact same query in both front ends?
    Here is the data set that I am testing for:
    <pre>
    id1 value
    smple_val_1 0
    smple_val_2 1
    smple_val_3 1
    smple_val_4 2
    smple_other_1 3
    smple_other_2 5
    smple_other_3 8
    smple_other_4 13
    some_other_val1 1
    some_other_val2 0
    some_other_val3 3
    some_other_val4 5
    </pre>
    I am trying to select only 'smple%' in the query, which should display in four columns like:
    <pre>
    id1 val1 id2 val2
    smple_val_1 1 smple_other_1 3
    smple_val_2 0 smple_other_2 5
    smple_val_3 0 smple_other_3 8
    smple_val_4 2 smple_other_4 13
    </pre>Is that really the output you want? Why not
    ID1             VAL1 ID2             VAL2
    smple_val_1        0 smple_other_1      3
    smple_val_2        1 smple_other_2      5
    smple_val_3        1 smple_other_3      8
    smple_val_4        2 smple_other_4     13with the 0's and 1's in the val1 column reversed?
    Here is the ddl I used:
    <pre>
    CREATE TABLE     table_x
    ( id     VARCHAR2 (20)     PRIMARY KEY
    , value     NUMBER
    INSERT INTO table_x (id, value) VALUES ('smple_val_1', 0);
    INSERT INTO table_x (id, value) VALUES ('smple_val_2', 1);
    INSERT INTO table_x (id, value) VALUES ('smple_val_3', 1);
    INSERT INTO table_x (id, value) VALUES ('smple_val_4', 2);
    INSERT INTO table_x (id, value) VALUES ('smple_other_1', 3);
    INSERT INTO table_x (id, value) VALUES ('smple_other_2', 5);
    INSERT INTO table_x (id, value) VALUES ('smple_other_3', 8);
    INSERT INTO table_x (id, value) VALUES ('smple_other_4', 13);
    INSERT INTO table_x (id, value) VALUES ('some_other_val1', 1);
    INSERT INTO table_x (id, value) VALUES ('some_other_val2', 0);
    INSERT INTO table_x (id, value) VALUES ('some_other_val3', 3);
    INSERT INTO table_x (id, value) VALUES ('some_other_val4', 5);
    </pre>Thanks, that's good.
    Where is the explanation of how you get the results you want from that data? There are a lot of different ways to get the same results from the same data, especially from a small set of sample data. I might provide a query that gets the right results for the wrong reasons, and when you run that query on a different set of data, it won't necessarily work. That's exactly what happened before. I guessed at what you wanted, but I guessed wrong. Guessing is not a very efficient or reliable way to solve problems. Don't make people guess: explain what you want.
    In particular, explain how you can tell, buy looking at a row and column in the original table, to which row and which column of the output it corresponds. I'm pretty sure that the id column of the table always corresponds to either the id1 or idl2 column of the output, and that value always corresponds to either val1 or val2. From this latest set of sample data, it looks like all the rows in table_x that start with 'smple_val' will correspond to the id1 and val1 columns, and that all therows that start with 'smple_other_' will correspond to the id2 and val2 columns. It also looks like each row of the output represents a unique value of the last character of table_x.id.
    If I guessed right this time, then what you want is:
    SELECT       MIN (CASE WHEN id LIKE 'smple\_val\_%'   ESCAPE '\' THEN id    END)     AS id1
    ,       MIN (CASE WHEN id LIKE 'smple\_val\_%'   ESCAPE '\' THEN value END)     AS val1
    ,       MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN id    END)     AS id2
    ,       MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN value END)     AS val2
    FROM       table_x
    GROUP BY  SUBSTR (id, -1)
    ORDER BY  SUBSTR (id, -1)
    ;But this is only a guess. I can't guarrantee that this will work on your real data any better than my last guess did. You'll get better answers faster if you provide an explanation, so that poeple don't have to guess so much.

  • SQL help, how to split one row into many rows

    Hi,
    I got a question on SQL. One table, structure like this: (2 columns)
    A 123,456,789
    B 012,345
    C 678,901,234
    How to get the final result like below:
    A 123,
    A 456,
    A 789
    B 012,
    B 345,
    C 678,
    C 901,
    C 234
    Do I have to use PL/SQL? Appreciate any thought you have on it!

    i doubt the second column string operation can be acheived within single query to break it into rows.
    but here is the pl/sql to do it.
    SQL> create table test_data(col1 varchar2(5), col2 varchar2(30))
      2  /
    Table created.
    SQL> insert into test_data values('A','123,456,789')
      2  /
    1 row created.
    SQL> insert into test_data values('B','012,345')
      2  /
    1 row created.
    SQL> insert into test_data values('C','678,901,234')
      2  /
    1 row created.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    pos   number:=0;
      3    str   test_data.col2%type;
      4  begin
      5    for i in (select col1, col2 from test_data)
      6    loop
      7      str := i.col2||',';
      8      loop
      9        pos := instr(str, ',');
    10        dbms_output.put_line(i.col1||' '||substr(str, 1, pos-1));
    11        str := substr(str, pos+1);
    12        exit when str is null;
    13      end loop;
    14    end loop;
    15  end;
    16  /
    A 123                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    A 456                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    A 789                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    B 012                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    B 345                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 678                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 901                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    C 234                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    PL/SQL procedure successfully completed.

  • Convert multiple rows to one row with multiple columns

    Hi
    i have a table Match_1 with 2 columns 'Source' and 'target'.One source can have multiple targets and that number could be anything
    CREATE TABLE Match_1
    Source CHAR(1),
    Target CHAR(1)
    INSERT INTO Match_1 VALUES ('A', 'B');
    INSERT INTO Match_1 VALUES ('A', 'C');
    INSERT INTO Match_1 VALUES ('A', 'D');
    INSERT INTO Match_1 VALUES ('A', 'E');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'Y');
    INSERT INTO Match_1 VALUES ('V', 'X');
    INSERT INTO Match_1 VALUES ('V', 'W');
    COMMIT;
    i need to get my output in the below format
    Source     target 1     target 2     target 3     target 4          target n
    A     B          C          D               
    V     X          Y          Z          W          
    Could you please provide me the required SQL.
    REgards
    -Learnsequel

    What is your database version (4 digit) ? also my example won't be generate columns for your information:
    it will produce a result like that :
    select source, listagg(target,',') within group (order by target)
      from  match_1
      group by source;
    A     B,C,D,E
    V     W,X,X,Yps: in previos post, I wrote "with" word wrong in sql.

  • Split one record into multiple records in Update Rules

    Hello All,
    I am trying to split a single record from R/3 into 2 records.
    My data flow is form R/3 > PSA > ODS > Cube
    when loading data into ODS i have to add the original record as it is to ODS. For second record i have to check a condition, & change few keyfigure values to 0 and fill an extra field.
    Example:
    Record in R/3 :
    Month | %1 | %2 | %3 | % 4 | ORGUNIT | JOB| EMPLOYEE| POSITION|
    02.2006 | 0 | 1 | 0 | 0 | 3000000| 248 | 2546352 | 500000 |
    Record in BW Comm_Structure.
    In Transfer rules i m writing an extra field to the R/3 record.
    Month | %1 | %2 | %3 | % 4 | ORGUNIT | JOB| EMPLOYEE| POSITION| NEW_FIELD |
    02.2006 | 0 | 1 | 0 | 0 | 3000000| 248 | 2546352 | 500000 | 2546352 |
    NEW_FIELD transfer routine :
    If employee NE 0
    Result  =  employee
    else.
    Result = 0 .
    Till this point everything works fine.
    Now i want to load this record into an ODS. I want to split the above single record into 2 records.
    Records in ODS should be :
    Month | %1 | %2 | %3 | % 4 | ORGUNIT | JOB| EMPLOYEE| POSITION| NEW_FIELD |
    02.2006 | 0 | 1 | 0 | 0 | 3000000| 248 | 2546352 | 500000 |  0 |
    02.2006 | 0 | 0 | 0 | 0 | 3000000| 248 | 2546352 | 500000 |  2546352 |
    Condition for NEW_FIELD.
    For first record always NEW_FIELD =0.
    For Second Record
    If NEW_FIELD NE 0.
    Cahnge KF's  %1, %2, %3, %4 = 0.
    If EMPLOYEE is 0 then no need to create extra record.
    I tried to use achieve this using return table, but no success.
    Can any one help me with ABAP syntax please. I am bit weak in ABAP Programming.
    Thanks in advance.
    POPS

    Dear:
    You could do so in update routines. Select the 'return table' option.
    useful links:
    https://forums.sdn.sap.com/click.jspa?searchID=10118555&messageID=2906656
    https://forums.sdn.sap.com/click.jspa?searchID=10118555&messageID=913873
    https://forums.sdn.sap.com/click.jspa?searchID=10118555&messageID=2441579
    Thanks

  • How to split one characteristic into 2 columns in query

    Hi,
    There is a characteristic TASK, which has a navigation attribute Phase Indicator, and if Phase Indicator = 1, then this Task is a Phase, or else it's a normal Task.
    Now I want to have a result with 2 columns like:
    Phase     Normal Task
    PH1        T1
    PH1        T2
    PH2        T3
    PH2        T4
    Could you give any advice on how to realize it?
    Thanks in advance!
    Regards,
    Napoleon

    Hi Napoleon,
    In ur query create 2 selections and give description as phase and normal task.
    In the 'phase' sleection drag 'task' as info object and give restriction for the nav attribute 'phase indicator' with 1.
    Similarly in the 'normal task' selection again drag 'task' as info object and give restriction for the nav attribute 'phase indicator' with not equal to 1.Hope it helps
    Regards,
    Rathy

  • Converting a single row into multiple columns

    Hi All,
    I have a hierarchy table. Sample values are
    Parent Child
    1
    1 2
    1 3
    2 4
    3 5
    2 6
    I have used the connect by clause to get the following listing using sys_connect_by_path
    /1/
    /1/2/
    /1/3/
    /1/2/4/
    /1/2/6/
    /1/3/5/
    But now I need them in seperate columns like
    c1 c2 c3
    1
    1 2
    1 3
    1 2 4
    1 2 6
    1 3 5
    Please help me in getting this resultset.
    Thanks
    Subbu S

    SQL> create table hierarchy_table
      2  as
      3  select 1 parent, 2 child from dual union all
      4  select null, 1 from dual union all
      5  select 1, 3 from dual union all
      6  select 2, 4 from dual union all
      7  select 3, 5 from dual union all
      8  select 2, 6 from dual
      9  /
    Tabel is aangemaakt.
    SQL> column s format a30
    SQL> column c1 format a5
    SQL> column c2 format a5
    SQL> column c3 format a5
    SQL> select s
      2       , substr
      3         ( s
      4         , nullif(instr(s,'|',1,1),0) + 1
      5         , nvl(nullif(instr(s,'|',1,2),0),4000) - instr(s,'|',1,1) - 1
      6         ) c1
      7       , substr
      8         ( s
      9         , nullif(instr(s,'|',1,2),0) + 1
    10         , nvl(nullif(instr(s,'|',1,3),0),4000) - instr(s,'|',1,2) - 1
    11         ) c2
    12       , substr
    13         ( s
    14         , nullif(instr(s,'|',1,3),0) + 1
    15         , nvl(nullif(instr(s,'|',1,4),0),4000) - instr(s,'|',1,3) - 1
    16         ) c3
    17    from ( select sys_connect_by_path(child,'|') s
    18             from hierarchy_table
    19          connect by parent = prior child
    20            start with parent is null
    21         )
    22  /
    S                              C1    C2    C3
    |1                             1
    |1|2                           1     2
    |1|2|4                         1     2     4
    |1|2|6                         1     2     6
    |1|3                           1     3
    |1|3|5                         1     3     5
    6 rijen zijn geselecteerd.Regards,
    Rob.

  • How can I split one row to multiple rows

    Table like this
    CREATE TABLE T(ID NUMBER(12),START_DATE DATE,END_DATE DATE,ORDER_ID NUMBER(12),PROD_ID NUMBER(12));
    data like this
    ID START_DATE END_DATE ORDER_ID PROD_ID
    1 2013-01-01 2013-03-31 12 123
    2 2013-04-01 2013-06-30 12 123
    3 2013-01-01 2013-05-30 12 234
    4 2013-02-01 2013-04-30 13 123
    5 2013-07-01 2013-09-30 13 345
    I want the result like this
    ID DIFF_DATE ORDER_ID PROD_ID
    1 201301 12 123
    2 201302 12 123
    3 201303 12 123
    4 201304 12 123
    5 201305 12 123
    6 201306 12 123
    7 201301 12 234
    8 201302 12 234
    9 201303 12 234
    10 201304 12 234
    11 201305 12 234
    12 201302 13 123
    13 201303 13 123
    14 201304 13 123
    15 201307 13 345
    16 201308 13 345
    17 201309 13 345
    how to write the sql ?
    Edited by: 990390 on 2013-3-31 下午11:42

    SQL> WITH t(iD ,START_DATE ,END_DATE ,ORDER_ID ,PROD_ID) AS(
      2  SELECT 1, to_date('2013-01-01','yyyy-mm-dd'), to_date('2013-03-31','yyyy-mm-dd'), 12, 123 FROM dual UNION ALL
      3  SELECT 2, to_date('2013-04-01','yyyy-mm-dd'), to_date('2013-06-30','yyyy-mm-dd'), 12, 123 FROM dual UNION ALL
      4  SELECT 3, to_date('2013-01-01','yyyy-mm-dd'), to_date('2013-05-30','yyyy-mm-dd'), 12, 234 FROM dual UNION ALL
      5  SELECT 4, to_date('2013-02-01','yyyy-mm-dd'), to_date('2013-04-30','yyyy-mm-dd'), 13, 123 FROM dual UNION ALL
      6  SELECT 5, to_date('2013-07-01','yyyy-mm-dd'), to_date('2013-09-30','yyyy-mm-dd'), 13, 345 FROM dual
      7  )
      8  SELECT add_months(MY_DATE , ROW_NUMBER() OVER(PARTITION BY Q.ORDER_ID, Q.PROD_ID ORDER BY ROWNUM)-1) ddate,
      9         Q.ORDER_ID,
    10         Q.PROD_ID
    11    FROM (SELECT MIN(T.START_DATE) MY_DATE,
    12                 MAX(T.END_DATE),
    13                 MONTHS_BETWEEN(MAX(T.END_DATE),MIN(T.START_DATE))+1 CNT,
    14                 T.ORDER_ID,
    15                 T.PROD_ID
    16            FROM t
    17           GROUP BY T.ORDER_ID, T.PROD_ID) Q,
    18         TABLE (SELECT COLLECT(ROWNUM) FROM DUAL CONNECT BY LEVEL <= Q.CNT)
    19   ORDER BY Q.ORDER_ID, Q.PROD_ID
    SQL> /
    DDATE         ORDER_ID    PROD_ID
    01.01.2013          12        123
    01.02.2013          12        123
    01.03.2013          12        123
    01.04.2013          12        123
    01.05.2013          12        123
    01.06.2013          12        123
    01.01.2013          12        234
    01.02.2013          12        234
    01.03.2013          12        234
    01.04.2013          12        234
    01.05.2013          12        234
    01.02.2013          13        123
    01.03.2013          13        123
    01.04.2013          13        123
    01.07.2013          13        345
    01.08.2013          13        345
    01.09.2013          13        345
    17 rows selected
    SQL> ----
    Ramin Hashimzadeh
    Edited by: Ramin Hashimzadeh on Apr 1, 2013 12:15 PM

  • 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

Maybe you are looking for

  • How do hook up printer

    I don't know how do hook my iPad up to my computer please help

  • RH7 WebHelp Output Missing TOC, Index, Search

    I updated my RH6 HTML project to RH7 HTML. When I publish, everything looks good. I uploaded all project files to my company's server, and a coworker saved those files to her computer. When my coworker publishes WebHelp from her computer, the TOC, In

  • AI Document-View synchronization issue

    My plugin works as following: 1. Delete a layer named "X1" 2. Add a layer "X1" and also add some art on that document 3. RedrawDocument() 4. SyncDocument from AIDocumentSuite 5. Saves changes through code 6. SyncDocument from AIDocumentSuite 7. Redra

  • My new iMac does not see my last iMac backup in Time Machine

    I just got a new iMac and I wanted to get my files from the time machine back up of my old iMac. Migration assistant did not see my iMac backup. It sees my Macbook backups, but not my iMac. My old iMac was running Yosemite Beta and the new one runs 1

  • G5 Dual won't boot from disk or from CD

    My computer froze this morning so I shut it down by holding the power button. When I try to power up the computer is sounds like the hard drive is spinning but I get no start up chime & no signal to the monitor. The power light on the front lights up