Converting single column content into rows

Hi All,
I have a table containing data in the following format
SNO Content
1 a,ab,aab,b,c
2 a,aac,aab,c,ccb,ee
3 bb,b,c
I have a requirement to convert this into following format
SNO Content
1 a
1 ab
1 aab
1 b
1 c
2 a
3 bb
3 b
3 c
How to acheive this in 10g? Is it possible in 9i?
Please share your thoughts.
Thanks in advance
Regards,
Subbu S

test@ORA92>
test@ORA92> @ver
BANNER
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE    9.2.0.1.0       Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
5 rows selected.
test@ORA92>
test@ORA92> select * from t;
       SNO CONTENT
         1 a,ab,aab,b,c
         2 a,aac,aab,c,ccb,ee
         3 bb,b,c
3 rows selected.
test@ORA92>
test@ORA92> select sno,
  2         rtrim(substr(lst,
  3                      instr(lst, ',', 1, iter.pos) + 1,
  4                      instr(lst, ',', 1, iter.pos + 1) - instr(lst, ',', 1, iter.pos)),
  5               ',') content
  6    from (select sno, ',' || content || ',' lst from t) csv,
  7         (select rownum pos from all_objects) iter
  8   where iter.pos <= ((length(csv.lst) - length(replace(csv.lst, ','))) / length(',')) - 1
  9   order by sno;
       SNO CONTENT
         1 a
         1 ab
         1 aab
         1 c
         1 b
         2 a
         2 aab
         2 ee
         2 ccb
         2 c
         2 aac
         3 bb
         3 c
         3 b
14 rows selected.
test@ORA92>
test@ORA92>Haven't tried this with a large number of rows, but I suspect it would be slow in that case. Regular expressions should make this simpler and more efficient in 10g.
Cheers,
pratz

Similar Messages

  • Re: Convert single column string to rows (CSV)

    Hi All
    I would appreciate some help here ... i am sure it is simple for many but the research i have done seems to ask for function that don't work in the db i am in.: 10.2.0.5.0
    Query is :
    SELECT '348419,348420,348421' from DUAL;
    Would like output to be:
    select from tb1;*
    output:
    348419
    348420
    348421

    Something like this...
    Ranit>> select * from a1;
    DAT                                                                            
    348419,348420,348421     
    Ranit>> select RTRIM(regexp_substr(dat,'(,)?[^,]+(,)?',1,level),',')
      2  from a1
      3  connect by level <= regexp_count(dat,'[,]')+1;
    RTRIM(REGEXP_SUBSTR(DAT,'(,)?[^,]+(,)?',1,LEVEL),',')                          
    348419                                                                         
    348420                                                                         
    348421                                                                         

  • 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 convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • Converting a single column table into a two-column table

    Hi everybody
    What I'm trying to do is convert a single column table into a two-column table. Here an example:
    Table A (single column):
    ID1
    ID2
    ID3
    ID4
    ID5
    Table B (two-column) should be:
    ID1 ID2
    ID3 ID4
    ID5
    I already did it by looping through a cursor and making an insert every 2 rows, but don't like performance.
    Is there an easier/faster way to do this?
    Thanks in advance
    Oscar

    with t as (
               select 'ID1' col1 from dual union all
               select 'ID2' from dual union all
               select 'ID3' from dual union all
               select 'ID4' from dual union all
               select 'ID5' from dual
              ) -- end of sample table
    select  col1,
            col2
      from  (
             select  col1,
                     lead(col1) over(order by col1) col2,
                     row_number() over(order by col1) rn
               from  t
      where mod(rn,2) = 1
    COL COL
    ID1 ID2
    ID3 ID4
    ID5
    SQL> SY.

  • Select single column but multiple rows in JTable

    Hi
    I have a jTable and want to be able to select multiple rows but only in a single column.
    I've set these properties which makes selection almost the way I would like it.
    table1.setCellSelectionEnabled(true);
    table1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);the only problem now is that the user can select multiple columns.
    Is there a simple way to restrict selection to single column?
    regards
    abq

    table.setCellSelectionEnabled(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    DefaultListSelectionModel model =
         (DefaultListSelectionModel)table.getColumnModel().getSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  • Converting comma separated string into rows

    for my procedure  varchar2 is i/p paramter. i will get this i/p from java. this string value is like  'VTP,VR','VM'.
    i want to split taht string into rows  ie o/p will be
    VTR
    VR
    VM.
    how to do this.

    Hi,
    As always, the solution depends on your data, your requirements, and you Oracle version.
    Here's one way:
    -- Simulating Java input with a bind variable:
    VARIABLE  str VARCHAR2 (100)
    EXEC     :str := 'VTP,VR,VM';
    SELECT  LEVEL  AS n
    ,       REGEXP_SUBSTR ( :str
                          , '[^,]+'
                          , 1
                          , LEVEL
                          ) AS str_part
    FROM     dual
    CONNECT BY LEVEL <= 1 + REGEXP_COUNT (:str, ',')
    I'm just guessing that your original string doesn't include single-quotes after VR or before VM.  If it does, you can use TRIM to remove them from the string passed back by REGEXP_SUBSTR.

  • Single column value into two column of report

    Hi frnds,
    I have a column of Adress in my databse table from where i have to fetch values and show it a report
    able to get report but showing in single column if i take a printout paper will be wasted so I thought of passing these values to two different columns
    please help me in giving some suggestions

    In Oracle 9 you can get rid of the regex functions and use traditional SUBSTR, INSTR and REPLACE:
    ABSOLUTELY NOT TESTED...
    SELECT col1,SUBSTR ( ','||col2||',', instr(','||col2||',',',',lvl)+1,instr(','||col2||',',',',lvl+1)-instr(','||col2||',',',',lvl)-1)
      FROM table_name,
           (SELECT LEVEL lvl
              FROM (SELECT MAX (LENGTH (REPLACE ( col2, ',',''))) mx
                      FROM table_name)
            CONNECT BY LEVEL <= mx + 1)
    WHERE lvl - 1 <= LENGTH (REPLACE ( col2, ',',''));Max

  • Sum of Table column contents into a last row with respect to column

    In a WebDynpro for java application,
      Need to sum up all the table with respect to column, at the last Row of the table with respect to column.
    Only one table should be present for contents as well for the total.
    Please help me.
    Edited by: devender vadithyabadabath on Jan 12, 2008 11:54 AM

    Hi,
    you must add e last element at the end of you Nodeelements.
    I<yourNode>Node node1 = wdContext.node<;yourNode>;
    I<yourNode>Element element = node1.create<;yourNode>element.;
    Iterate over the your node element to build your sum of each and than add this sum to the last row of your table.
    element.set<;yourAttribute>(sum);
    node1.addElement(element);
    I hope this helps
    regards
    Gunter

  • Converting column data into rows in oracle 10g

    sample data:
    PATID NA2     NA3     NA4     
    1     3     4     5     
    1     34     45     56     
    1     134     245     356     
    2     134     245     356     
    2     334     275     56     
    2     4     275     56     
    2     4     5     56     
    how to display the above data like
    PATID NA2 NA3 NA4
    1 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4
    3 34 134 4 45 245 5 56 356
    2 134 134 4 4 245 275 275 5 356 56 56 56

    Many examples are here:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    (and you can do a search on this forum as well to find more)
    edit
    Your sample data is not very clear, by the way.
    Please post a CREATE TABLE and some INSERT statements, just enough to put up the testcase.
    Use the tag before and after posting examples, so formatting will be maintained.
    See the [FAQ|http://forums.oracle.com/forums/help.jspa] for more information regarding tags (scroll a bit down)...
    Edited by: hoek on Jan 26, 2010 5:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Converting Single Instance database into Oracle Fail-Safe on Linux

    Hi All,
    We have single instance Oracle10g database running on Linux RHEL4. We are looking to convert this database into Oracle Fail-Safe (Active-Passive). Does any one have document for Oracle fail-safe setup?
    Regards,
    Tushar

    Tushar,
    you can't use software for windows on Linux.
    However, there's number of ways to implement high-availability solution on Linux Oracle.
    You can go with Active-Active (RAC) - which means that you'll have two servers attached to the same database at the same time. You can use either, and if one goes down(due to power failure for instance), the second will still be available.
    You can go with Active-Passive (Data Guard) - which means that you'll have one of the nodes being active and the second passive, but synchronized with the first one, so in case of failure of the first node you can activate the second one.
    You can also go with linux clustering - which is most similar to MCS + fail-safe - you'll have two nodes clustered with linux clustering software (RH cluseter suite for instance) and connected to shared storage. One node is active, and in case of crash database instance will be automatically started on the second node. This is beneficial because you can use your resources more efficiently. In case if you have two databases you can run each of them on dedicated server and then, in case of node failure move to another one. However, the setup of such configuration is quite cumbersome.

  • Converting Smartforms output content into HTML File

    Hi,
    I have a requirement, Smartforms output contents needs be converted as HTML File and it should be sent as email.
    I am able to get the Smartforms output in html format but the output is shown as binary format.
    After the fm call the job_output_info parameter is holding the smartforms output content in
    job_output_info-XMLOUTPUT[]           (xsf content)
    job_output_info-XMLOUTPUT-STSHEET[]   (css content)
    job_output_info-XMLOUTPUT-TRFRESULT[] (html content)
    Help me out how to handle the job_output_info details to html format.
    Code
    DATA v_fm_name TYPE rs38l_fnam.
    DATA v_tdsfname TYPE tdsfname VALUE 'ZVR39_SF'.
    DATA output_options TYPE ssfcompop.
    DATA job_output_info TYPE ssfcrescl.
    DATA document_output_info TYPE ssfcrespd.
    DATA job_output_options TYPE ssfcresop.
    DATA w_control TYPE ssfctrlop.
    *-Finding the Smartform Layout Name
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = v_tdsfname
      IMPORTING
        fm_name            = v_fm_name
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.
    *-Defining the output to HTML Format
    *-Activating XSF Output
    output_options-xdfcmode   = 'X'.
    output_options-xdf        = space.
    output_options-xsfcmode   = 'X'.
    output_options-xsf        = 'X'.
    output_options-xsfoutmode = 'A'. "
    output_options-xsfoutdev  = 'P863'.
    output_options-xsfformat  = 'X'.
    *-Calling the Smartform Layout
    CALL FUNCTION v_fm_name
      EXPORTING
        output_options       = output_options
        user_settings        = 'X'
      IMPORTING
        document_output_info = document_output_info
        job_output_info      = job_output_info
        job_output_options   = job_output_options
      EXCEPTIONS
        formatting_error     = 1
        internal_error       = 2
        send_error           = 3
        user_canceled        = 4
        OTHERS               = 5.
    Giri

    Hi,
    Check this link.In that,I am converting the output of smartform to PDF and then attaching it through mail.
    https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/smartforms/smartform in abap.pdf

  • Convert MS word content into xstring

    Hello to all,
    I want to pass on the file name of a word document to a function module, which in turn will read the contents of this file into an xstring variable.
    Please apprise if anyone knows a fm for the same.
    P.S : I am aware that there exists an UI element (file_upload) through which we can select the desired file and then it gets stored in the context's attribute of type xstring. I want the same thing to be replicated without using the UI elemnt (fileupload).

    hi abheee,
    www.towersperrin.com/tp/getwebcachedoc?webc=TILL/GBR/2007/200705/Update_FMUE.pdf
    go thru this url. u may get the necessary info.
    reward me if it is help full to u.
    thanks
    karthikeya

  • Date & time  difference in a single column but multiple rows in a table

    hi folks,
    am using Oracle db 10g by chance is there any other way to do my requirement.
    as I stated in my subject.

    You probably need LAG:
    SQL> -- generating sample data (how hard can it be...)
    SQL> with testdata as (
      2  select 200 bno, 32 temperature, to_date('28.05.2012 09:00:00', 'dd.mm.yyyy hh24:mi:ss') dt from
    dual union
      3  select 200, 36,to_date('28.05.2012 15:00:00', 'dd.mm.yyyy hh24:mi:ss') from dual
      4  )
      5  --
      6  -- actual query:
      7  --
      8  select bno
      9  ,      temperature
    10  ,      dt
    11  ,      numtodsinterval(dt-lag(dt) over (partition by bno order by dt), 'day') difference_int
    12  ,      substr((numtodsinterval(dt-lag(dt) over (partition by bno order by dt), 'day')), 12, 8)
    difference_dt
    13  from   testdata;
           BNO TEMPERATURE DT                  DIFFERENCE_INT                 DIFFEREN
           200          32 28-05-2012 09:00:00
           200          36 28-05-2012 15:00:00 +000000000 06:00:00.000000000  06:00:00
    2 rows selected.But, as Paulie already said: still insufficient input. We know nothing about your datatypes. I assumed you're using a DATE.

  • Comma separated column values into row values

    Hi all,
    i am selecting the data from TABLE A ( id number ,rights varchar2 ). result set as
    ID     RIGHTS
    1     M,P,Y,N,C,P
    4     N,E,A
    10     N,C,R,P
    but i want the output as
    ID     RIGHTS
    1     M
    1 P
    1 Y
    1 N
    1 C
    1 P
    4     N
    4 E
    4 A
    10     N
    10 C
    10 R
    10 P
    kindly share your idea's to get the desired results.
    thanks in advance
    Edited by: 887268 on Nov 30, 2012 11:12 PM

    Try this
    SQL> WITH a(id, rights) AS
      2  (
      3  SELECT 1, 'M,P,Y,N,C,P' FROM dual UNION ALL
      4  SELECT 4, 'N,E,A' FROM dual UNION ALL
      5  SELECT 10, 'N,C,R,P' FROM dual)
      6  SELECT id, regexp_substr(rights, '[^,]+',1,level) res
      7  FROM a
      8  CONNECT BY  level - 1 <= regexp_count(rights,',')  /*  regexp_count:- 11g */
      9  AND prior id = id
    10  AND prior sys_guid() IS NOT NULL /* sys_guid:- 11g */
    11  ORDER BY id
    12  /
            ID RES
             1 M
             1 P
             1 Y
             1 N
             1 C
             1 P
             4 N
             4 A
             4 E
            10 N
            10 R
            ID RES
            10 C
            10 P
    13 rows selected.Thanks!
    Edited by: Ashu_Neo on Dec 1, 2012 9:43 PM
    -- Added comment

Maybe you are looking for