How to convert multiple lines in 1 row of columns across

Hello

My DB 10g

My data as below,
84A8E46E9366     20111008133638
84A8E46E9366     20111112000531
84A8E46E9366     20111212004432
84A8E46E9366     20120127173533
84A8E46E9366     20120226235444
I've already tilt it by
select 
msid,
rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee
from 
aaa_bill
where msid='84A8E46E9366'
and fee is not null
group by 
msid;
and get the result as below with only 2 column
84A8E46E9366     20111008133638|20111112000531|20111212004432|20120226235444|20120127173533
but I need the result to be on multiple columns.
so I tried the following
select msid,REGEXP_SUBSTR ( fee
           , '^[^|]*'
           )
from 
(
select 
msid,
rtrim (xmlagg (xmlelement (e, fee || '|')).extract ('//text()'), '|') fee
from 
aaa_bill
where msid='84A8E46E9366'
and fee is not null
group by 
msid
)
;
but the result, only the first string

84A8E46E9366 20111008133638


is it possible to get Thos on several columns each string on column separated automatically because I have about 20000 msid separate

Hello

See the FAQ forum: {message identifier: = 9360005}

In Oracle 10, you can do this:

WITH     got_c_num     AS
(
     SELECT     msid
     ,     fee
     ,     ROW_NUMBER () OVER ( PARTITION BY  msid
                               ORDER BY          fee     -- or whatever
                       ) AS r_num
     FROM     aaa_bill
     WHERE     ...
)
SELECT       msid
,       MIN (CASE WHEN c_num = 1 THEN fee END)     AS col_1
,       MIN (CASE WHEN c_num = 2 THEN fee END)     AS col_2
,       MIN (CASE WHEN c_num = 3 THEN fee END)     AS col_3
...
,       MIN (CASE WHEN c_num = n THEN fee END)     AS col_n
FROM       got_c_num
GROUP BY  msid
ORDER BY  msid     -- If wanted
;

Note that you must specify the number of columns in the output. If you are unsure, do a high hypothesis. The query works always; unused columns will be NULL.

Published by: Frank Kulash on 12 March 2012 14:45

Tags: Database

Similar Questions

  • How to convert multiple lines in a row in oracle?

    There is output

    status st_nm County
    AN OPEN 12
    A NARROW 13
    B OPEN 1
    B CLOSE 2

    EXPECTED RESULTS
    st_nm OPEN_count CLOSE_COUNT

    A 12 13
    1 2 B

    give the possibility of solutions?

    Published by: 886380 on September 30, 2011 05:53

    Published by: 886380 on September 30, 2011 05:54

    Published by: 886380 on September 30, 2011 05:56

    Hello

    This is called a Pivot .
    Here's a way to do it:

    SELECT       st_nm
    ,       MIN (CASE WHEN status = 'OPEN'  THEN cnt END)     AS open_count     -- COUNT by itself is not a good column name
    ,       MIN (CASE WHEN status = 'CLOSE' THEN cnt END)     AS close_count
    FROM       existed
    GROUP BY  st_nm;
    

    The best way depends on your exact requirtements and your version of Oracle. (The query above will work in Oracle 8.1 and higher).
    For more information, see the FAQ for the forum page:
    SQL and PL/SQL FAQ

  • Convert multiple lines in a row

    Hello

    DB version: 10.2.0.3

    It's the entry

    NAMETotalFree
    ITEM115050
    ITEM2200175

    Expected result:

    Please tell how to get the result in format (SQL using case or nested case) below

    (XXX_utilized columns is on Total - free)

    ITEM1_TOTALITEM1_UtilizedITEM1_FreeITEM2_TOTALITEM2_UtilizedITEM2_Free
    1501005020025175

    Kind regards

    Veera

    with

    the entry like

    ("ITEM1" select name, 150 total, 100 50 used, free of all the double union)

    Select 'ITEM2', 200, 25, 175 double

    )

    SELECT max (case name when total ' ITEM1' then end) item1_total,.

    Max (case name when 'ITEM1' then used end) item1_utilized,.

    Max (case name when free ' ITEM1' then end) item1_free,.

    Max (case name when total ' ITEM2' then end) item2_total,.

    Max (case name when 'ITEM2' then used end) item2_utilized,.

    Max (case name when free ' ITEM2' then end) item2_free

    Since the entry

    ITEM1_TOTAL ITEM1_UTILIZED ITEM1_FREE ITEM2_TOTAL ITEM2_UTILIZED ITEM2_FREE
    150 100 50 200 25 175

    Concerning

    Etbin

  • merge multiple lines in a row (but multiple columns)

    How to merge multiple lines in a row (but several columns) effectively.

    For example

    IDVal IDDesc Id_Information_Type Attribute_2 Attribute_3 Attribute_4 Attribute_5 Attribute_1 IdNum
    23 asdc 1 location USA NM ABQ four seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    AAFC 65 2 location USA TX AUS Hilton 92305
    65 AAC 2 Stats 5510 42.7 46 9999
    AAFC 65 2 Audit 1996 July 172 1100


    where different attributes mean different for each Information_type.
    For example, for Information_Type = location
    Attribute_1: countries
    Attribute_2: State and so on.


    For example, for Information_Type = Stats
    Attribute_1 designates the Population
    Attribute_2: percentage of ethnicity American and so on.

    I want to create a view that shows as below:

    IDVal IDDesc IDNum country state city hotel ZipCode American Population % other % area Audit year Audit AuditMonth Type AuditTime
    23 asdc 1 USA NM ABQ reviews 87106 2300 91.7 46 85432 1996 June 17 1200
    AAFC 65 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100


    Thank you

    Hello

    This is called pivoting . The FAQ forum has a section on this subject: {message identifier: = 9360005}

    I hope that answers your question.
    If not, post your best attempt, as well as some examples of data (CREATE TABLE and INSERT, only relevant columns instructions) and also publish outcomes from these data. (See you the desired results, but they are very difficult to read because they are not formatted. Use \.

     tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    
  • How to add multiple lines when the button is clicked

    How to add multiple lines when the click on button now is just add a row .plz give me idea how... waiting for answer

    / public final class screen extends MyScreen
    {
    /**
    * Creates a new object of MyScreen
    */
    ObjectChoiceField obj1 obj2, obj3, obj4.
    Table of String() = {'101 ', ' 102'};
    String of shadow [] = {"Shade1", "Shade2"};
    Rolls of string [] = {'101 ', ' 102'};
    String cutting [] = {"100-150", "150-200"};
    Chain of selectedindex1, selectedindex2, selectedindex3, selectedindex4;
    LabelField lbl1 lbl2, lbl3, lbl4;
        
    GFM LinedGridFieldManager;
    HFM HorizontalFieldManager, hfm1, hfm2 hfm3;
    VerticalFieldManager vfmMain;
        
    public MyScreen()
    {
        
    Set the displayed title of the screen
    hfm1 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    hfm2 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    hfm3 = new HorizontalFieldManager (HorizontalFieldManager.NO_VERTICAL_SCROLL |) HorizontalFieldManager.NO_VERTICAL_SCROLLBAR);
    HFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_RIGHT);
    vfmMain = new VerticalFieldManager (Manager.NO_VERTICAL_SCROLL |) Manager.NO_HORIZONTAL_SCROLLBAR);
            
    obj1 = new ObjectChoiceField ("", graph, 0, FIELD_LEFT);
    obj2 = new ObjectChoiceField ("", blind, 0, FIELD_LEFT);
    Obj3 = new ObjectChoiceField ("", rolls, 0, FIELD_LEFT);
    Obj4 = new ObjectChoiceField ("", cuts, 0, FIELD_LEFT);
            
    LBL1 = new LabelField("");
    LBL2 = new LabelField("");
    lbl3 = new LabelField("");
    lbl4 = new LabelField("");
            
    ButtonField btnAdd = new ButtonField ("ADD", FIELD_RIGHT);
            
    GFM = new LinedGridFieldManager (4, LinedGridFieldManager.VERTICAL_SCROLL);
            
    hfm1.setMargin (20, 0, 10, 0);
    hfm1. Add (new LabelField ("Chart"));
    hfm1. Add (obj1);
    hfm1. Add (new LabelField ("Shade"));
    hfm1. Add (obj2);
            
    hfm2. Add (new LabelField ("Rolls"));
    hfm2. Add (Obj3);
    hfm2. Add (new LabelField ("Cuts"));
    hfm2. Add (Obj4);
    HFM. Add (btnAdd);
            
    GFM. Add (new LabelField ("Chart"));
    GFM. Add (new LabelField ("Shade"));
    GFM. Add (new LabelField ("Rolls"));
    GFM. Add (new LabelField ("Cuts"));
            
    vfmMain.add (hfm1);
    vfmMain.add (hfm2);
    vfmMain.add (hfm3);
    vfmMain.add (hfm);
    vfmMain.add (new SeparatorField());
    vfmMain.add (gfm);
    Add (vfmMain);
            
    btnAdd.setChangeListener (new FieldChangeListener()
    {
    ' Public Sub fieldChanged (field field, int context) {}
    TODO self-generating method stub
    selectedindex1 = chart [obj1.getSelectedIndex ()];
    selectedindex2 = shade [obj2.getSelectedIndex ()];
    selectedindex3 = rolls [obj3.getSelectedIndex ()];
    selectedindex4 = cuts [obj4.getSelectedIndex ()];
                    
    While (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
    {
    LBL1. SetText (selectedindex1);
    LBL2. SetText (selectedindex2);
    lbl3. SetText (selectedindex3);
    lbl4. SetText (selectedindex4);
                    
    GFM. Add (LBL1);
    GFM. Add (LBL2);
    GFM. Add (lbl3);
    GFM. Add (lbl4);
                    
    }
    }
    });
    }
    }

    Hi Piya,

    I run your code, and according to your logic that it works correctly.

    It's adding that line only once because according to your logic that one line can be added to MDT, if you do not want to add line on each click on the button, follow these steps:

    selectedindex1 = chart [obj1.getSelectedIndex ()];
    selectedindex2 = shade [obj2.getSelectedIndex ()];
    selectedindex3 = rolls [obj3.getSelectedIndex ()];
    selectedindex4 = cuts [obj4.getSelectedIndex ()];

    Lbl1 LabelField = new LabelField("");
    Lbl2 LabelField = new LabelField("");
    LabelField lbl3 = new LabelField("");
    LabelField lbl4 = new LabelField("");
    If (LBL1. GetText(). Equals("") | LBL2. GetText(). Equals("") | lbl3. GetText(). Equals("") | lbl4. GetText(). Equals(""))
    {
    LBL1. SetText (selectedindex1);
    LBL2. SetText (selectedindex2);
    lbl3. SetText (selectedindex3);
    lbl4. SetText (selectedindex4);
                    
    GFM. Add (LBL1);
    GFM. Add (LBL2);
    GFM. Add (lbl3);
    GFM. Add (lbl4);
                    
    }

  • How to insert multiple lines using a single query

    Hi all

    How to insert multiple lines using a single query to the emp table?
    I have the number of rows to insert into table x. consumes a lot of time. I tried to insert several lines using a single query, but get errors. I know exactly the query to do this.


    Thank you
    Sunil

    Like this?

    SQL> create table test(id number , dt date);
    
    Table created.
    
    SQL> insert into test values(&a,&b);
    Enter value for a: 1   --- It asked me and I entered 1
    Enter value for b: sysdate  --- It asked me and I entered sysdate
    old   1: insert into test values(&a,&b)
    new   1: insert into test values(1,sysdate)
    
    1 row created.
    
    SQL> 
    

    g.

  • Convert multiple lines in a single value separated by commas

    Is is possible to convert multiple lines in a single value by concatenating the value of each line in OBIEE. I think that IO had seem a blog related to this by I'm not able to find him. Essentially, here's what I would do:
    Number of customer location
    101
    101 NY
    101 PA
    102 TX
    102 CA

    This is to convert
    101. HE, NY, PA
    102 TX, CA

    Can you get it someone please let me know if this is possible and how to operate it.

    Thanks in advance for the help.

    You can do this by creating a DB function,

    Visit this link
    Re: Display of the horizontal values

    Thank you
    Vino

  • How to get the string (specified by row and column) of txt file with labview

    Hello world

    How to get the string (specified by row and column) of txt file with labview

    THX

    As far as I know, a text file has no column.  Be more specific.  Do you mean something like the 5th word on line 4, where the words are separated by a space, and lines are separated by a newline character?  You can read from the spreadsheet String function and set the delimiter to a space.  This will produce a 2D channels table.  Then use the table to index and give the line number and column number.

  • How to convert my toolbar in 2 rows so that all my icons and apps to show?

    How to convert my toolbar so that it appears on two lines?

    Hello

    1. which version of the Windows operating system is installed on your computer?

    2. are you referring to the toolbar or the task bar?

    3. If you are referring to the Internet Explorer toolbar, which version of Internet Explorer is installed on your computer?

    If you are referring to the taskbar, then try the steps in the following Microsoft article and check if it helps.

    Change appear on the taskbar buttons:

    http://Windows.Microsoft.com/en-us/Windows7/change-how-buttons-appear-on-the-taskbar

    The taskbar (overview):

    For Windows 7: http://Windows.Microsoft.com/en-us/Windows7/the-taskbar-overview

    For Windows Vista: http://windows.microsoft.com/en-US/windows-vista/The-taskbar-overview

    For Windows Vista: http://windows.microsoft.com/en-US/windows-vista/Taskbar-recommended-links

    And see also: Suggestions for a question on help forums:

    http://support.Microsoft.com/kb/555375

    Hope the information is useful, if you are referring to the Internet Explorer toolbar, then just reply to us for additional help.

  • How to convert multiple photos stored as layers in a sequence in the timeline using the CC of the PS?

    I would like to be able to convert multiple photos of a subject in video high resolution using the timeline in PS CC.

    Here's how you can import a folder of images which become images in a video layer.
    Using Photoshop | Import video files and image sequences

  • How to convert multiple DNG size full of lossy DNG in Lightroom?

    Hello

    When I select several DNG in Lightroom and my mac, go to menu > library > convert photo to DNG and then choose Convert to DNG with the lossy mode, only the selected DNG is converted. How to convert more at the same time? I have a large library, and I want to convert ~ 100 GB of photos at a loss.

    Thanks in advance!

    How to convert more at the same time? I have a large library, and I want to convert ~ 100 GB of photos at a loss.

    Using Photos of the library/convert to DNG, if you're in something other than the display of the grid, one photo will be converted even if several are selected.  Its the same way that all orders (perhaps not all) work in library mode, you must be in mode grid for multiple photo stock.

  • How to create the table with the rows and columns using the layout?

    One of my friends advised me to put my site on the mode of provision as it is better than the standard as he said
    but I couldnot make an ordinary table with the rows and columns in mode available th
    y at - there someone who can tell me how to?
    Thank you very much

    Wednesday, April 18, 2007 21:01:38 + 0000 (UTC), "Mr.Ghost".
    wrote:

    > A friend of mine advised me to put my whole site on the mode of disposal as its
    > better than standard, as he says

    Your friend won't. Don't listen to him any more. Mode of disposal creates
    very fragile and rigid code pauses at the first opportunity.

    Gary

  • How to convert (multiple) output lines (multi-column)


    HII


    I have a weird request. But not sure how to get results out of it!


    My query returns two rows to a query I asked.



    Current result
    10
    20

    Expected result

    10 20

    My problem here is that I wanted two values above to be stored in two variables in a single select statement.



    If I use a cursor that my problem will be solved. But I'm not much interested in using a cursor for a simple select statement.



    is there a possibility that I can convert the output of two lines to two columns?



    I use Oracle Release 10.1.0.2.0



    Windows Xp operating system.



    People here will not appreciate the tags 'Urgent '. I know that :-(.



    But some how I'm forced to use this tag "urgent." Sorry for that.



    If no response, I will in another way can go to the slider :-(



    Any help will be appreciated.



    Thank you
    Pavan

    ??? WITH the clause is just a quick way to produce one on the fly table with your sample data. I think you should do a lot of reading material. In any case, use:

    select  dept,
            max(decode(rn,1,location,null)) location_1,
            max(decode(rn,2,location,null)) location_2
      from  (
             select  dept,
                     location,
                     row_number() over(partition by dept order by location) rn
               from  (
                      your-query
                     )
            )
      group by dept
    /
    

    SY.

  • How to insert multiple lines in viewobject with primary key?

    Hello

    I use Jdeveloper 11.1.1.3.0 version.

    I create object entity based on the table of the database that have primary keys.
    I created the view on this entity object. I created an array of viewobject, with CreatInsert button and my primary key in the table may while the new record is added.

    Now my problem is that I have created several rows by pressing CreateInsert Button several rows of time are created and displayed in the table. I insert data in all columns of all rows when I click on the submit button (who have the Action "# {bindings.Commit.execute} ') will save data of any 1 line not all data line.

    How can I save all the lines that is created in a single transaction?

    Thanks in advance
    Amit

    Amit,

    I just tried this (all by default, no code written), and he recorded all of the lines. It must be something unique to your application. Michael asks a lot of questions.

    John

  • How to convert the lines into columns dynamically

    HII
    I have a 'report_line' with the following data table

    location_code line_code value
    LOC1 L1 12
    loc2 L1 13
    LOC1 L2 15
    loc2 L3 11
    LOC3 L1 9

    Now I want the o/p by converting the line_codes in clumns as below

    L1 L2 L3
    LOC1 12 15
    13 11 loc2
    LOC3 9

    How can I do this dynamically. Line codes are not constatnt, they can change for each scenario.

    Thank you
    Sandeep

    I want just a sql for this query and no. columns ' maximum of are 6.

    In this case you can do.

    --sample data
    with t
    as
    (
    select 'loc1' location_code, 'L1' line_code, 12 value from dual union all
    select 'loc2', 'L1', 13 from dual union all
    select 'loc1', 'L2', 15 from dual union all
    select 'loc2', 'L3', 11 from dual union all
    select 'loc3', 'L1', 9 from dual
    )
    --end of sample data
    select location_code,
           max(decode(line_code, 'L1', value, null)) L1,
           max(decode(line_code, 'L2', value, null)) L2,
           max(decode(line_code, 'L3', value, null)) L3,
           max(decode(line_code, 'L4', value, null)) L4,
           max(decode(line_code, 'L5', value, null)) L5,
           max(decode(line_code, 'L6', value, null)) L6
      from t
     group by location_code
    

    Here I used the WITH clause as an example of table. You can replace the "t" table name in the select statement with your actual table and remove the WITH clause.

Maybe you are looking for