One Column into Rows

I have data in a table that looks like below:
ColumnA               ColumnB
123                    abc|cde|fgr
345                    def|ght|sew
890                    deq|nmk|lop|lip|fre|dwsThere is no limit on how many values you can have in ColumnB and they are pipe delimited.
I need to split this one column into rows as:
ColumnA               ColumnB
123                    abc
123                    cde
123                    fgr
345                    def
345                    ght
890                    fre
890                    dwsThanks in advance!

with sample_data as (
                     select 123 columna,'abc|cde|fgr' columnb from dual union all
                     select 345,'def|ght|sew' from dual union all
                     select 890,'deq|nmk|lop|lip|fre|dws' from dual
select  columna,
        regexp_substr(columnb,'[^|]+',1,column_value) columnb
  from  sample_data,
        table(
              cast(
                   multiset(
                            select  level
                              from  dual
                              connect by level <= length(regexp_replace(columnb || '|','[^|]'))
                   as sys.OdciNumberList
  order by columna,
           column_value
   COLUMNA COLUMNB
       123 abc
       123 cde
       123 fgr
       345 def
       345 ght
       345 sew
       890 deq
       890 nmk
       890 lop
       890 lip
       890 fre
   COLUMNA COLUMNB
       890 dws
12 rows selected.
SQL> SY.

Similar Messages

  • Converting columns into rows

    Dear all....I need to convert all columns into rows in a table. For example table has following columns:
    Emp_Cod........Val1......Val2......Val3
    1 a b c
    Now I wish that each column should display as a value like:
    Emp_Cod........Val1
    1 a
    1 b
    1 c
    Now the one way to solve this job is to write a union statement for each column but for this I'll have to write equal number of select statements as there are columns.
    What I need that is there anyway to write minimum code for this job, is there any alternate way???

    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t unpivot(v for c in(val1,val2,val3));
    EMP_CODE  C     V                                                      
            1  VAL1  a                                                      
            1  VAL2  b                                                      
            1  VAL3  c                                                      
    SQL> col COLUMN_VALUE for a20
    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t,table(sys.odcivarchar2list(val1,val2,val3));
    EMP_CODE  V  V  V  COLUMN_VALUE                                        
            1  a  b  c  a                                                   
            1  a  b  c  b                                                   
            1  a  b  c  c                                                   

  • Transpose columns into rows

    hi ,
    i need to transpose columns into rows ,
    i know i can use the UNION ALL but my num of columns will most likely not be fixed so how can i do that ?
    pls advise

    This is from one of the forms link,, i reallyy dont know the link, but i guess this is "adrains" code
    SQL> WITH ilv AS (
      2      SELECT str || ','                                   AS str
      3      ,     (LENGTH(str) - LENGTH(REPLACE(str, ','))) + 1 AS no_of_elements
      4      FROM   t
      5      )
      6  SELECT RTRIM(str, ',')                              AS original_string
      7  ,      SUBSTR(str, start_pos, (next_pos-start_pos)) AS single_element
      8  ,      element_no
      9  FROM  (
    10         SELECT ilv.str
    11         ,      nt.column_value AS element_no
    12         ,      INSTR(
    13                   ilv.str,
    14                   ',',
    15                   DECODE(nt.column_value, 1, 0, 1),
    16                   DECODE(nt.column_value, 1, 1, nt.column_value-1)) + 1 AS start_pos
    17         ,      INSTR(
    18                   ilv.str,
    19                   ',',
    20                   1,
    21                   DECODE(nt.column_value, 1, 1, nt.column_value)) AS next_pos
    22         FROM   ilv
    23         ,      TABLE(
    24                   CAST(
    25                      MULTISET(
    26                         SELECT ROWNUM FROM dual CONNECT BY ROWNUM < ilv.no_of_elements
    27                         ) AS number_ntt )) nt
    28        );
    ORIGINAL_STRING                 SINGLE_ELEMENT  ELEMENT_NO
    X,Y,Z                           X                        1
    X,Y,Z                           Y                        2
    X,Y,Z                           Z                        3
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  XXX                      1
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  Y                        2
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  ZZ                       3
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  AAAAA                    4
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  B                        5
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  CCC                      6
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  D                        7
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  E                        8
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  F                        9
    XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG  GGG                     10
    13 rows selected.
    Note that the above SQL performs the following steps:
        * determines how many elements are in each string (WITH clause);
        * for each string, generates a collection of n elements (TABLE expression), where n is the derived number of elements in the string. Note in particular the use of "less than" in the "CONNECT BY ROWNUM < ilv.no_of_elements" on line 26. In all versions other than 10.1.x, this will need to be "CONNECT BY ROWNUM <= ilv.no_of_elements" (i.e. "less than or equal to"). There is an unusual bug with this row-generation technique in 10.1 that generates an additional row from the CONNECT BY;
        * uses the generated rows in a Cartesian Product with the original data to generate n rows per string, based on the above definition of n;
        * calculates the start and end position of each element in each string (INSTR); and
        * cuts each element from each string (SUBSTR).

  • Splitting one column into 4 columns

    Hi,
      I want to split one column into 4 columns as shown below.
    parameters
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP12100173&YearYear=2013&Source=1&UserID=aac6440
    it should be display as 
    panel                      yearyear                source              userid
    MP01110201           2013                            1                    aad2779
    MP12100173           2013                            1                    aac6440
    there will be thousands of rows in the column. Can anybody help how to split it as shown.The length may very from row to row
    Thanks for your help.........
    BALUSUSRIHARSHA

    It is working...thank u very much... I found one more issue here
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP11100070&Source=1&PNR=2&YearYear=2014&UserID=ddc1535
    PanelPanel=MP11101276&Source=1&YearYear=2014&PNR=2&UserID=ddc1565
    I found 3 kinds of formats in the same column... I didn't observe the data carefully while posting the
    question..sorry about that. In this case if we need to show as
    panel                      yearyear                source
                 userid
    MP01110201           2013                            1                    aad2779
    MP11100070           2014                           1                    ddc1535
    MP11101276           2014                
              1                    ddc1565
    is it possible to filter like this? Should we use any case statement in query while we have diff formats
    like this?
    BALUSUSRIHARSHA

  • How to combine a one columns into 1?

    I am using Oracle 8i,
    I want to know that how to combine a one columns into 1 row:
    For example:
    ITEM_NO NAME
    01 ABC
    01 CDE
    Result Set:
    ITEM_NO NAME
    01 ABC; CDE
    I have try to use "SYS_CONNECT_BY_PATH" this function, however, that function can use in Oracle 9i or 10g, NOT 8i.
    So please please help me to solve that. Many thanks.

    Check this thread
    Re: column values separated by ,

  • Problem in displaying the data of columns into rows in sap script

    hi,
    i am working on a sap script and i have to display the dat which is displayed in column into rows but it is not displaying it properly.
    eg, C
        12.1
        Si
        5.5
    it is displaying the data right now like this but i want to display the  data like this:-
    eg, C      Si
        12.1   5.5
    plzzprovide me guidelines how to solve this problem.

    hi,
    i am using this code to display the data:-
    plzz provide me guidelines where i am getting wrong?
    TOPparCOMPONENT DESP,,,,,, INS. LOT #, , , , , , MIC,,,,,,,,,, MIC VALUEparENDTOPparFINAL
    PROTECT
    IF &I_FINAL-PRUEFLOS& NE '000000000000'
    &I_FINAL-MAKTX(23)&&i_final-prueflos(12Z)&
    &I_FINAL-kurztext(25)&
    &I_FINAL-original_input(8)&
    ELSE
    &I_FINAL-MAKTX(23)&     
    &I_FINAL-kurztext(25)&
    &I_FINAL-original_input(8)&
    ENDIF
    ENDPROTECT
    ITEMHEAD
    POSITION WINDOW
    SIZE WIDTH +0 . 4 CH HEIGHT +1 LN
    BOX FRAME 10 TW
    BOX HEIGHT '1.35' LN INTENSITY 20
    IF &PAGE& = '1'
    BOX XPOS '0' CH YPOS '0' CM WIDTH '0' CM HEIGHT '43' LN FRAME '10' TW
    For horizontal line at top
    BOX XPOS '0' CH YPOS '0' CM WIDTH '75' CH HEIGHT '0' LN FRAME '10' TW
    COLUMN LINES...
    END OF COLUMN LINES...
    BOX XPOS '0' CH YPOS '43' LN WIDTH '75' CH HEIGHT '0' LN FRAME '10'TW
    BOX XPOS '75' CH YPOS '0' LN WIDTH '0' CH HEIGHT '43' LN FRAME '10'TW
    ELSE
    COLUMN LINES...
    END OF COLUMN LINES...
    BOX XPOS '0' CH YPOS '0' CM WIDTH '0' CM HEIGHT '47' LN FRAME '10' TW
    BOX XPOS '0' CH YPOS '0' CM WIDTH '75' CH HEIGHT '0' LN FRAME '10' TW
    BOX XPOS '0' CH YPOS '0' CM WIDTH '45' CM HEIGHT '0' LN FRAME '10' TW
    BOX XPOS '20' CH YPOS '0' CM WIDTH '0' CM HEIGHT '47' LN FRAME '10' TW
    BOX XPOS '0' CH YPOS '47' LN WIDTH '75' CH HEIGHT '0' LN FRAME '10'TW
    BOX XPOS '75' CH YPOS '0' LN WIDTH '0' CH HEIGHT '47' LN FRAME '10'TW
    ENDIF
    LINEFEED
    NEWPAGE
    NEW-PAGE
    provide me guidelines to solve this problem.
    Edited by: ricx .s on Mar 13, 2009 5:58 AM

  • How to add one column into the t.code: cat2

    Hi
    I am userexits
    here i want to add one column into the t.code: cat2 at particular location, and that added field have to display the data what i am selcting in that transaction.
    how to do this...
    thankx

    hi,
        CATS0005           
        CATS0007           
        CATS0009        
        CATS0010        
        CATS0012.
        Go through the documentations of above Enhancements to solve ur problem. I am not able to understand ur exact requirement. that is y i gave some more Enhancements.

  • ALV to select more than one column by row using set_table_for_first_display

    Hello everyone,
    I am developing an application (ALV OO) to select more than 1 column by row ( one ). This is an a holiday application so the idea is:
    -One column will be the day, and the row will be the user.
    So I am trying to select more than one day by user (that would be the row).
    I am using the method set_table_for_first_display but when it shows the alv, doesn't let me to select more than one column with a click of the mouse.
    Does anybody know if I can do this (select more than one column, by row) in somehow?
    Please let me know if you need more clarification about this.
    Thanks in advance
    Diego

    Hi Diego,
    it's all in the documentation.
    set different selection modes through the value of the field u201CSEL_MODEu201D in the layout structure.
    SPACE
    same as 'B'
    see 'B'
    Default setting
    'A'
    Column and row selection
    Multiple columns
    Multiple rows
    The user selects the rows through pushbuttons at the left border of the grid control.
    'B'
    Simple selection, list box
    Multiple columns
    Multiple rows
    'C'
    Multiple selection, list box
    Multiple columns
    Multiple rows
    'D'
    Cell selection
    Multiple columns
    Multiple rows
    Any cells
    The user selects the rows through pushbuttons at the left border of the grid control
    Beyond setting this option, you can set u201CNO_ROWMARKu201D option to hide the mark column which is normally visible when the selection mode allows multiple row selection.
    One point to notice here is that if you set your ALV Grid as to be editable, it may override your selection mode regardless of your layout settings.
    This is from SDN Community Contribution "An Easy Reference for ALV Grid Control" By: Serdar ŞİMŞEKLER
    Sorry, no link,. it's on my disk.
    Regards,
    Clemens

  • How to display the rows in to columns and columns into rows?

    DES:- I know by using pivot and unpivot you can convert rows into columns and columns into rows but i don't know how to write the syntax?

    Hi,
    Besides the places Martin mentioned above, there are many examples in the forum FAQ:
    https://community.oracle.com/message/9362005#9362005
    For an example of both PIVOT and UNPIVOT in the same query, see
    http://forums.oracle.com/forums/thread.jspa?threadID=920854&tstart=0

  • How can I separate one column into multiple column?

    How can I separate one column into multiple column?
    This is what I have:
    BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
    0001 PHONE_NUMBER 555-555-0001
    0001 EMAIL [email protected]
    0001 CURRENCY USD
    0002 PHONE_NUMBER 555-555-0002
    0002 EMAIL [email protected]
    0002 CURRENCY USD
    0003 PHONE_NUMBER 555-555-0003
    0003 EMAIL [email protected]
    0003 CURRENCY CAD
    This is what I would like to have:
    BUYER_ID PHONE_NUMBER EMAIL CURRENCY
    0001 555-555-0001 [email protected] USD
    0002 555-555-0002 [email protected] USD
    0003 555-555-0003 [email protected] CAD
    Any help would be greatly appreciated.

    This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
    CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
    then you will type this procedure:
    declare
    phone_number_v varchar2(50);
    EMAIL_v varchar2(50);
    CURRENCY_v varchar2(50);
    cursor my_test is select * from test;
    begin
    for my_test_curs in my_test loop
    select ATTRIBUTE_VALUE INTO phone_number_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='PHONE_NUMBER';
    select ATTRIBUTE_VALUE INTO EMAIL_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='EMAIL';
    select ATTRIBUTE_VALUE INTO CURRENCY_v from test
    where person_id=my_test_curs.person_id
    and attribute_name ='CURRENCY';
    INSERT INTO test2
    VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
    END LOOP;
    END;
    Then you will create your final table like this:
    create table final_table as select * from test2 where 1=2;
    After that write this code:
    INSERT ALL
    into final_table
    SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
    FROM TEST2;
    If you have a huge amount of data in your original table this solution may take a long time to do what you need.

  • To convert columns into row

    Hi All,
    I need help in building view which actually can show columns data as row.
    e.g.
    row is as follows
    Name Age Salary
    ABC 25 10000
    BBC 28 12000
    The above tables data I want to get as
    Name ABC BBC
    Age 25 28
    Salary 10000 12000
    Thanks in advance.

    Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
    Re: Converting Columns into rows
    Nicolas.

  • How to turn columns into rows

    Hi. Does anyone know how to turn columns into rows ie:
    select field1, field2, field3, field4, field5 from table
    desired result:
    field1 field2
    field1 field3
    field1 field4
    field1 field5
    Thank you!

    Something like this ?
    select field1
    , case n.l
    when 1 then field2
    when 2 then field3
    when 3 then field4
    when 4 then field5
    end field
    from table
    , (select level l from dual connect by level <= 4) n

  • Convert single column into rows

    hi Gurus,
    I have one table test colums are id and name.
    id number
    name varchar2
    data is like
    id name
    1 xy
    2 xyy
    3 mm
    4 pp
    Now my requirement is to convert single column id into rows
    i,e my output should be of singel rows like :- 1,2,3,4
    How to achive this result .
    I dont have any idea to do this query.
    Please help guys.
    Thanks in advance.
    Vijay

    Well,
    As long as your code doesn't have to run in production, simplest way is:
    WM_CONCAT (but it's not documented)
    or use XMLAGG, it's simpler than a connect by:
    MHO%xe> with t as (
      2  select 1 col, 'xy' str from dual union all
      3  select 2, 'xyy' from dual union all
      4  select 3, 'mm'from dual union all
      5  select 4, 'pp' from dual union all
      6  select 8, 'pp' from dual union all
      7  select 12, 'pp' from dual union all
      8  select 40, 'pp' from dual
      9  )-- actual query, based on id's generated above:
    10  select rtrim(xmlagg(xmlelement(e,col||',')).extract('//text()'),',') col
    11  from   t;
    COL
    1,2,3,4,8,12,40
    1 rij is geselecteerd.

  • How to split columns into rows

    Hi All,
    Below is my table structure:=
    SQL> create table split(id number,value varchar2(200));
    Table created.
    SQL> insert into split values(1,'X,Y,Z');
    1 row created.
    SQL> insert into split values(2,'A,B,C');
    1 row created.
    SQL> commit;
    Commit complete.
    Expected Output
    ID Value
    1 X
    1 Y
    1 Z
    2 A
    2 B
    3 C
    I know the feature of converting rows into columns by listagg in Oracle 11g, but is there any feature to convert rows into columns based on a delemiter..."," in my case.
    Please help....
    Thanks
    Arijit

    >
    is there any feature to convert rows into columns based on a delemiter
    >
    Here is one way
    VAR csv VARCHAR2(100)EXEC :csv := 'abc,de,fg,hij,klmn,o,pq,rst,uvw,xyz';
    The query:
    WITH data AS( SELECT SUBSTR(csv, INSTR(csv,',',1,LEVEL)+1,                     INSTR(csv,',',1,LEVEL+1) - INSTR(csv,',',1,LEVEL)-1 ) token    FROM ( SELECT ','||:csv||',' csv FROM SYS.DUAL ) CONNECT BY LEVEL < LENGTH(:csv)-LENGTH(REPLACE(:csv,',',''))+2 )SELECT token  FROM data;See http://projectwownow.blogspot.com/2010/02/oracle-convert-csv-string-into-rows.html

  • Table with column group (one column) - next row is showing on new page instead of below previous row

    I am creating new table. My goal is to display some text in few lines like this:
    "AAAAAAAA"           "BBBBBBBB"           "CCCCCCCCC"     
    "DDDDDDD"           "EEEEEEEE"
    Actually the next row (with "DD" and "EE" values) is not displayed below first row, but on the next page.
    I've tried to put table into rectangle, disabled all page breaks and still the same effect. Any help?

    Hi Heidi,
    Actually, it's not solution, I only gave more details about my problem :)
    Another description:
    In my report I'm creating Tablix with Column grouping. There is only one column with image (every image has same width). If there is only three pictures, then they are displayed next to each other in one row.
    In case, there is more than three pics, another row is showing on next page. I'd like to display all rows one after another on one page.
    I've tried to create three vertical lists, and filter each column group to display only records:
    1) =(RowNumber("Tablix1")) mod 3 = 1
    2) =(RowNumber("Tablix1")) mod 3 = 2
    3) =(RowNumber("Tablix1")) mod 3 = 0
    Unfortunately, I got an error:
    "A FilterExpression for the tablix ‘Tablix1’ uses the function RowNumber.  RowNumber cannot be used in filters."
    Do You have any other propositions?
    --------EDIT--------
    ok, I manged to solve it. As I said, I've created three vertival lists and placed them next to each other.
    Then, instead of using filter, I've used Visibility trigger:
    1)
    =IIf(RunningValue(Fields![rowgroupfield].Value, COUNTDISTINCT, "Tablix1") mod 3 = 1, false, true)
    2)
    =IIf(RunningValue(Fields![rowgroupfield].Value, COUNTDISTINCT, "Tablix2") mod 3 = 2, false, true)
    3)
    =IIf(RunningValue(Fields![rowgroupfield].Value, COUNTDISTINCT, "Tablix3") mod 3 = 0, false, true)
    I had to use function RunningValue to count all occurrences, as my report is quite complex and "RowNumber" [ssrs function] and "ROW_NUMBER() OVER (ORDER BY [rowgroupfield])" [sql query] were not working properly.

Maybe you are looking for