How to convert  columns into rows

present result
Mat_num        comp_code   disc          amount     
800000     SG01      SAPLF005                    0.00
800000     SG01      SAPLF005               31,500.00
6300001    SPM       SAPLF005                    0.00
6300001    SPM       SAPLF005              108,888.00
APS100     SMTP      SAPLF005                    0.00
APS100     SMTP      SAPLF005                    0.00
required format
Mat_num       disc             SG01          SMTP          SPM
800000   SAPLF005   31,500.00           0.00          0.00
800000   SAPLF005        0.00           0.00          0.00 
6300001  SAPLF005        0.00         0.00     108,888.00     
6300001  SAPLF005        0.00         0.00           0.00  
APS100   SAPLF005        0.00         0.00           0.00 
APS100   SAPLF005        0.00         0.00           0.00
Plain Text Attachment [ Scan and Save to Computer ]
REPORT  Z_CALC2                                 .
TABLES : KNC1.
TYPE-POOLS: SLIS.
  type-pools : abap.
field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.
data: dy_table type ref to data,
      dy_line  type ref to data,
      xfc type lvc_s_fcat,
      ifc type lvc_t_fcat.
DATA: BEGIN OF ITAB OCCURS 0,
          KUNNR LIKE KNC1-KUNNR,
          BUKRS LIKE KNC1-BUKRS,
          GJAHR LIKE KNC1-GJAHR,
          USNAM LIKE KNC1-USNAM,
          UMSAV LIKE KNC1-UMSAV,
      END OF ITAB.
*Result table
TYPES BEGIN OF RES_ITAB.
* RES_ITAB(10) TYPE C DEFAULE 'ZRES_ITAB'.
INCLUDE STRUCTURE ZRES_ITAB.
TYPES END OF RES_ITAB.
SELECT-OPTIONS : CCODE FOR KNC1-BUKRS DEFAULT 'SG01' TO 'SPM '.
DATA : BEGIN OF COMP_ITAB OCCURS 0,
          BUKRS LIKE KNC1-BUKRS,
       END OF COMP_ITAB.
DATA: COLS TYPE I,
      gap(10) TYPE c,
      Company_title type string .
start-of-selection.
  perform get_NUM_COLS.
  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
*  perform write_out.
FORM GET_NUM_COLS.
SELECT KUNNR BUKRS GJAHR USNAM UMSAV INTO TABLE ITAB FROM KNC1 WHERE
BUKRS IN CCODE.
CLEAR ITAB.
*CLEAR RES_ITAB.
LOOP AT ITAB .
     COMP_ITAB-BUKRS = ITAB-BUKRS.
     APPEND COMP_ITAB.
CLEAR COMP_ITAB.
ENDLOOP.
SORT COMP_ITAB BY BUKRS.
DELETE ADJACENT DUPLICATES FROM COMP_ITAB.
DESCRIBE TABLE COMP_ITAB LINES COLS.
ENDFORM.
*Get table structure
form get_structure.
data : idetails type abap_compdescr_tab,
       xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
data fld_pos type i value 1.
* Get the structure of the table.
  ref_table_des ?=
              cl_abap_typedescr=>describe_by_name( 'ZRES_ITAB' ).
  idetails[] = ref_table_des->components[].
  loop at idetails into xdetails.
    clear xfc.
    XFC-COL_POS = fld_pos.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
    fld_pos = fld_pos + 1.
  endloop.
  DO  COLS TIMES.
    clear xfc.
    READ TABLE COMP_ITAB INDEX SY-INDEX.
    XFC-COL_POS = fld_pos.
    xfc-fieldname = COMP_ITAB-BUKRS .
    xfc-datatype = 'F'.
*    xfc-inttype = 'F'.   'details-type_kind.
    xfc-intlen = 14.
*    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
    fld_pos = fld_pos + 1.
  ENDDO.
  clear xfc.
    XFC-COL_POS = fld_pos.
    xfc-fieldname = 'RECORD_TOTAL' .
    xfc-datatype = 'F'.
    xfc-inttype  = 'F'.
    xfc-intlen = 14.
*    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
               exporting
                  it_fieldcatalog = ifc
               importing
                  ep_table        = dy_table.
  assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.
endform.
form get_data.
LOOP AT ITAB.
        <DYN_WA>-KUNNR = ITAB-KUNNR.
        <DYN_WA>-USNAM = ITAB-USNAM.
        DO COLS TIMES.
           IF <DYN_WA>
DESCRIBE TABLE <dyn_table>.
*WRITE:/ SY-TFILL.
* Select Data from table.
* <dyn_table> = ITAB[].
*LOOP AT ITAB.
*    RES-KUNNR = ITAB-KUNNR.
*    RES-USNAM = ITAB-USNAM.
*    CASE ITAB-GJAHR.
*        WHEN 2005.
*            RES-UMSAV1 = ITAB-UMSAV.
*        WHEN 2006.
*            RES-UMSAV2 = ITAB-UMSAV.
*        WHEN 2007.
*            RES-UMSAV3 = ITAB-UMSAV.
*    ENDCASE.
*    RES-TOTAL = RES-UMSAV1 + RES-UMSAV2 + RES-UMSAV3 .
* APPEND RES.
*ENDLOOP.
endform.
form write_out.
  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component  sy-index
         of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        write:/ <dyn_field>.
      else.
        write: <dyn_field>.
      endif.
    enddo.
  endloop.
endform.
Edited by: Alvaro Tejada Galindo on Feb 28, 2008 11:56 AM

solved myself

Similar Messages

  • How to convert columns into rows using  transpose function

    Hi
    anybody tell me how to convert columns values into rows using transpose function.

    Since BluShadow went to all the trouble to put it together, someone should use it.
    See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
    John

  • 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

  • How to convert columns to rows

    I have 70 columns and I need to convert them into rows. Please help!
    Currently, it is showing as listed below
    message 1 message 2 message 3 message 4 message 5 .......... message 70
    system 1 20 10 40 60 100
    system 2 40 30 50 80 110
    system 3 60 60 70 90 120
    The desire output
    system 1 system 2 system 3
    message 1 20 40 60
    message 2 10 30 60
    message 3 40 50 70
    message 70

    Something like...
    SQL> ed
    Wrote file afiedt.buf
      1  select decode(rn,1,'Empno :'||empno
      2                  ,2,'Ename ('||empno||') :'||ename
      3                  ,3,'Job ('||empno||') :'||job
      4               ) as col
      5  from emp
      6       cross join (select rownum rn from dual connect by rownum <= 3)
      7* order by empno, rn
    SQL> /
    COL
    Empno :7369
    Ename (7369) :SMITH
    Job (7369) :CLERK
    Empno :7499
    Ename (7499) :ALLEN
    Job (7499) :SALESMAN
    Empno :7521
    Ename (7521) :WARD
    Job (7521) :SALESMAN
    Empno :7566
    Ename (7566) :JONES
    Job (7566) :MANAGER
    Empno :7654
    Ename (7654) :MARTIN
    Job (7654) :SALESMAN
    Empno :7698
    Ename (7698) :BLAKE
    Job (7698) :MANAGER
    Empno :7782
    Ename (7782) :CLARK
    Job (7782) :MANAGER
    Empno :7788
    Ename (7788) :SCOTT
    Job (7788) :ANALYST
    Empno :7839
    Ename (7839) :KING
    Job (7839) :PRESIDENT
    Empno :7844
    Ename (7844) :TURNER
    Job (7844) :SALESMAN
    Empno :7876
    Ename (7876) :ADAMS
    Job (7876) :CLERK
    Empno :7900
    Ename (7900) :JAMES
    Job (7900) :CLERK
    Empno :7902
    Ename (7902) :FORD
    Job (7902) :ANALYST
    Empno :7934
    Ename (7934) :MILLER
    Job (7934) :CLERK
    42 rows selected.

  • 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                                                   

  • 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

  • How to convert column to row in 10g  and calculate the count

    876602 wrote:
    Hi ,
    i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
    this is sample of my date ,
    MDN             Date
    5C4CA98EABA3     20111205235240
    5C4CA98EABA3     20110925121833
    5C4CA98EABB0     20111025103700
    5C4CA98EABB0     20111124103700
    5C4CA98EABB5     20111030175717
    5C4CA98EABB8     20110925142653
    5C4CA98EABB8     20111126175853i need the result to be ,
    MDN             Date                                   count
    5C4CA98EABA3     20111205235240 ;  20110925121833    2
    5C4CA98EABB0     20111025103700 ;  20111124103700    2
    5C4CA98EABB5    20111030175717                      1
    5C4CA98EABB8   20110925142653 ; 20111126175853       2any help please ,
    Edited by: 876602 on 15/12/2011 01:33 ص

    SQL> with t as
      2  (
      3  select '5C4CA98EABA3' MDN ,'20111205235240' Dte  from dual
      4  union all
      5  select '5C4CA98EABA3','20110925121833' from dual
      6  union all
      7  select '5C4CA98EABB0','20111025103700' from dual
      8  union all
      9  select '5C4CA98EABB0','20111124103700' from dual
    10  union all
    11  select '5C4CA98EABB5','20111030175717' from dual
    12  union all
    13  select '5C4CA98EABB8','20110925142653' from dual
    14  union all
    15  select '5C4CA98EABB8','20111126175853' from dual
    16  )
    17  select mdn,ltrim(sys_connect_by_path(dte,';'),';') s,rw as "count"
    18  from
    19  (
    20  select mdn,dte,row_number() over(partition by mdn order by mdn) rw
    21  from t
    22  )
    23  where connect_by_isleaf = 1
    24  start with rw = 1
    25  connect by prior rw = rw-1
    26  and prior mdn = mdn
    27  ;
    MDN          S                                                                                     count
    5C4CA98EABA3 20111205235240;20110925121833                                                             2
    5C4CA98EABB0 20111025103700;20111124103700                                                             2
    5C4CA98EABB5 20111030175717                                                                            1
    5C4CA98EABB8 20110925142653;20111126175853                                                             2

  • How to convert column to row in 10g

    Hi ,
    i need to convert the column to row in my DB 10g , i cant use the Decode method because i have about 2000 items in MDN column
    this is sample of my date ,
    MDN             Date
    5C4CA98EABA3     20111205235240
    5C4CA98EABA3     20110925121833
    5C4CA98EABB0     20111025103700
    5C4CA98EABB0     20111124103700
    5C4CA98EABB5     20111030175717
    5C4CA98EABB8     20110925142653
    5C4CA98EABB8     20111126175853i need the result to be ,
    MDN             Date
    5C4CA98EABA3     20111205235240 ;  20110925121833 
    5C4CA98EABB0     20111025103700 ;  20111124103700
    5C4CA98EABB5    20111030175717
    5C4CA98EABB8   20110925142653 ; 20111126175853any help please ,
    Edited by: 876602 on 15/12/2011 01:33 ص

    Note the name of this forum is "SQL Developer *(Not for general SQL/PLSQL questions)*", so only for issues with the SQL Developer tool. Please post these questions under the dedicated {forum:id=75} forum.
    Regards,
    K.

  • Convert columns into rows

    SQL>create table TEST1
    TRAIN_ID VARCHAR2(10) not null,
    ALIES VARCHAR2(15),
    VAL VARCHAR2(20)
    Now I insert data into test1 table.
    SQL> select* from test2;
    TRAIN_ID NAM DOB
    A ASHIS 11/11/1974
    B SOUGATA 20/06/1977
    Now how can I select data in the following
    output ? Please suggest me.
    TRAIN_ID ALIES VAL
    A NAM ASHIS
    A DOB 11/11/1974
    B NAM SOUGATA
    B DOB 20/06/1977

    SELECT *
      FROM(
    SELECT tran_id, 'NAM' alies, nam val
      FROM test2
    UNION ALL
    SELECT tran_id, 'DOB' alies, TO_CHAR(dob, 'DD/MM/YYYY') val
      FROM test2
    ORDER BY tran_idwould appear to do what you want, though I'm not sure why you'd want it. Note that you'll have to convert all the values to a single data type (in this case VARCHAR2), which would make operating on the data quite painful later on...
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Convert Columns into Rows (internal tables) - Urgent Help Pleasse..

    Hi friends i'm having a little problem and hope you can help me..Here's the situation.
    I have an internal table like shown below
    (Key)                   (Key)               (Key)          (Key)
    PATH_ID     |      GROUP     |      LINE     |     ATRIBUTE          |    VALUE
    ASLN2                1                      1                Company_Code       5146
    ASLN2                1                      1                Account_Code        400405
    ASLN2                1                      1                Profit_Centre          AA00N2
    ASLN2                1                      2                Company_Code       5146
    ASLN2                1                      2                Account_Code       400705
    ASLN2                1                      2                Profit_Centre          AA00N2
    ASLN3                1                      1                Company_Code       5146
    ASLN3                1                      1                Account_Code        400405
    ASLN3                1                      1                Profit_Centre          AA00N2
    ASLN3                1                      2                Company_Code       5146
    ASLN3                1                      2                Account_Code       400705
    ASLN3                1                      2                Profit_Centre          AA00N2
    and i want to convert this internal table to one like below
    PATH_ID      |      GROUP      |      LINE     |      Company Code   |    Account Code    |    Profit Centre
    ASLN2                1                      1                 5146                     400405                   AA00N2
    ASLN2                1                      2                 5146                     400705                   AA00N2
    ASLN3                1                      1                 5146                     400405                   AA00N2
    ASLN3                1                      2                 5146                     400705                   AA00N2
    but i'm a bit of stuck, all those key fields are making me confused...anyone have a marvelous ( ) idea of how to implement this transformation ?
    best regards,
    Ricardo Monteiro

    Itab1 with the structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
    Itab2 with structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
    Itab3 with the final structure PATH_ID | GROUP | LINE | Company Code | Account Code | Profit Centre
    move itab1 to itab2.
    sort itab2 by path_id group line.
    delete adjacent duplicates from itab2 comparing path_id group line.
    loop at itab2.
      clear itab3.
      move:
         itab2-pathid to itab3-pathid,
         itab2-group to itab3-group,
         itab2-line to itab3-line.  
      loop at itab1where pathid = itab2-pathid
                            and group = itab2-group
                            and line   = itab2-line.
          IF itab1-ATRIBUTE = ' Company_Code'.
             itab3-Company_Code = itab1-attribute.
          elseif itab1-ATRIBUTE = ' Account_Code '.
             itab3-Account_Code = itab1-attribute.
          elseif itab1-ATRIBUTE = ' Profit_Centre ' .
             itab3-profit_center = itab1-attribute.
          endif
      endloop.
      append itab3.
    endloop.
    try this.
    Thanks,
    rajinikanth

  • 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

  • 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 convert BLOB into a String

    Hi,
    I got a blob column from the database.
    It contains one XML File.
    How to convert it into String.
    I need the code for how to convert the blob into String
    Thanks in Advance.

    A blob would be a byte-array, which you can use in the String(byte[]) constructor

  • 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).

Maybe you are looking for