Concatenate items from different rows

We are looking for an aggregate function similiar to the 'count' function, however instead of counting the distinct occurances, we want to concatenate them together into one single string.
i.e.
TestTable:
ID Name
1 A
1 B
1 C
2 A
2 F
SELECT ID, makestring(Name) FROM TestTable;
Produces:
1 ABC
2 AF
If possible please reply by e-mail to:
[email protected]
Any help with this is appreciated
Mark Emerson

Mark: I think this is not the best solution in performance, but it can help you like a beginning:
create or replace function makestring (v_id number) return varchar2
is
cursor c is select Name from TestTable
where id=v_id;
str varchar2(10):='';
begin
for r in c loop
str:=str | | r.Name;
end loop;
return str;
end;
You must use the DISTINCT clause, like this:
SELECT DISTINCT id, makestring(id) FROM TestTable;
This SELECT display the results that you are looking for. The main problem of this function is the size of the TestTable, and It will be important to consider create an index in the ID column, if doesn't exist yet (and to be sure of its use, using hints if it's necessary). Bye and good luck.

Similar Messages

  • SUM two fileds from different rows from the same table

    I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
    E.g.
    BillingTransactionsIndex      CreateDate      UserType      UserIndex      TransType      Reference      Total      Balance
    2      6/5/2008 15:02      1      51      1      150      -288.2      -288.2
    5      6/8/2008 11:55      1      51      1      157      -1.58674      -289.787
    In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
    Please help
    Thanks

    SQL> with tbl as
      2  (select 1 as ID,  90 as total from dual
      3          union all
      4  select 2 as ID,  23 as total  from dual
      5          union all
      6  select 3 as ID,  15 as total  from dual
      7          union all
      8  select 4 as ID,  20 as total  from dual)
      9  select id , total, sum(total) over (order by ID) as balance from tbl
    10  /
            ID      TOTAL    BALANCE
             1         90         90
             2         23        113
             3         15        128
             4         20        148
    SQL>

  • TEXT ITEM from different table

    When a TEXT ITEM from different table exists in the DATA BLOCK,
    and when after EXECUTE_QUERY (in trigger POST_QUERY) we issue
    the SELECT for filling the TEXT ITEM from different table, how
    we can prevent FROM_STATUS and RECORD_STATUS to get the
    value "CHANGED" (because othervise COMMIT is updating all the
    records which are the result of EXECUTE_QUERY)?

    Set the record status back to query in Post Query trigger:
    SET_RECORD_PROPERTY(:SYSTEM.TRIGGER_RECORD, 'BLOCK_NAME', STATUS
    , QUERY_STATUS);

  • Reference Items from different pages

    Hey Guys,
    I have a short question:
    How can I reference Items from a different page?
    I have a query, which references to a datepicker from another page.....
    Can anybody help?
    Thanks,
    Tim

    Tim,
    just as you would reference the item on the same page.
    The current value is written to session state.
    For example, you datepicker on page 1 is called P1_DATE1.
    Then you can reference is using the usual methods on page 2:
    select v('P1_DATE1') from dual;
    select :P1_DATE1 from dual;
    select '&P1_DATE1.' from dual;~Dietmar.

  • Concatenate strings from more rows into one row.

    Hi,
    what's the name of that analytical function (or connect by) that
    would return strings from more rows as one row concatenated. i.e.:
    (I know this is possible using regular pipelined functions.)
    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    select tadah().... from ...
    result:
    ROW1: STR1 STR2 STR3Thanks.

    Hi,
    Here's a basic example of SYS_CONNECT_BY_PATH.
    The query below produces one row of output per department, containing a list of the employees in that department, in alphabetioc order.
    WITH     got_rnum     AS
         SELECT     ename
         ,     deptno
         ,     ROW_NUMBER () OVER ( PARTITION BY  deptno
                                         ORDER BY          ename
                              ) AS rnum
         FROM     scott.emp
    --     WHERE     ...          -- Any filtering goes here
    SELECT     deptno
    ,     LTRIM ( SYS_CONNECT_BY_PATH ( ename
                                  , ','     -- Delimiter, must never occur in ename
               )          AS ename_list
    FROM     got_rnum
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     rnum          = 1
    CONNECT BY     rnum          = PRIOR rnum + 1
         AND     deptno          = PRIOR deptno
    ;Output:
    .   DEPTNO ENAME_LIST
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARDThe basic CONNECT BY query would produce one row per employee, for example:
    .   DEPTNO ENAME_LIST
            10 ,CLARK
            10 ,CLARK,KING
            10 ,CLARK,KING,MILLER
            20 ,ADAMS
            20 ,ADAMS,FORD
    ...The WHERE clause: <tt>WHERE CONNECT_BY_ISLEAF = 1</tt> means that we'll only see the last row for every department.
    SYS_CONNECT_BY_PATH (which is a row function, by the way, not an analytic fucntion) puts a delimiter (',' in the example above) before every item on the list, including the first one.
    The query above uses LTRIM to remove the delimiter at the very beginning.
    WM_COMCAT (or the equivalent user-defined STRAGG, which you can copy from AskTom) is much more convenient if order is not important.

  • Invoking Javascript with Items from Different Page

    I have a two page application. "Page 1" has a Javascript function to which I pass ITEMS from Page 1.
    Can I include Items from "Page 2" in this function ?
    thanks
    abhay

    I need to pass three arguments to a Javascript function. The first two are the values of two ITEMS on Page 1.
    The function is being called from Page 1.
    Is it possible to pass value of an item which is on Page 2 ?
    ak.

  • Selecting from different rows

    Hi all,
    The database is Oracle10g.
    I want to select one column from one row of a table, based on a condition, and the second column of the second row of that first row of the same table.
    There should be an order by clause to enable it so that I can talk about first row and second row.
    For example : select ename , job from emp where deptno = 20; . And here the column ename is for the first employee of deptno 20 , and job is the column for the second employee in the same deptno.
    How to achieve this ?
    Thank you very much indeed

    I think you want this.
    SQL> create table test as select rownum id,'ROW '||rownum r from all_objects where rownum<=5;
    Table created.
    SQL> select * from test order by id;
            ID R
             1 ROW 1
             2 ROW 2
             3 ROW 3
             4 ROW 4
             5 ROW 5
    SQL> select id,r,lead(r,1) over (order by id) next_r from test order by id;
            ID R          NEXT_R
             1 ROW 1      ROW 2
             2 ROW 2      ROW 3
             3 ROW 3      ROW 4
             4 ROW 4      ROW 5
             5 ROW 5The feature you are looking for is analytic functions. You can read about them here: http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/analysis.htm#sthref1684

  • How to Delete Item from Front Row?

    Someone sent me a short imovie project and it was automatically downloaded to my "Download" folder. When I opened Front Row, the project name it's right under "Movies" along with "iTunes Top Movies", "Theatrical Trailers" and "Movie Folder".
    I then moved the project file from "Download" to another folder created under my "Movie" folder. When I went to Front Row again, the original project was still under the list in Movies, now it's also in "Movies Folder". So basically it's showing up twice in Front Row in different places.
    I see that once I play the movie from my Movies folder directly from the folder, it's automatically set to Music/iTunes/iTunes Media/Movies. So it's showing up in Front Row via iTunes, and it's also showing in Front Row via my Movies Folder.
    I just want to organize Front Row so that I don't have a long list of projects immediately under "Movies" in Front Row. I want these projects to neatly go in one personal movie folder only.
    Is there a way to reorganize the items list in Front Row?
    How do I delete the item that's originally placed under "Movies" in Front Row?

    Assets are organized in various apps - primarily iTunes for most of us.
    That said, you may benefit from this series:
    http://www.macnewsworld.com/story/59317.html

  • Working with items from different tables

    I have a form with item P1_A whose source is from database column that is from database table A.
    How do create another item P1_B whose source is from another database column that is from database table B? This item P1_B is on the same form where P1_A is on.
    How do I set the Fetch Row from table process to fetch P1_A from table A and to fetch P1_B from table B?
    How do I set the Process Row of table process to update/insert/delete row from table A and from table B simultaneously?

    I create my own row fetch process with a sequence number higher than the Automated Row Fetch process. So, it does the following in the correct order:
    1) It fetches all columns in table A via the Automated Row Fetch process and display them on page 7, and then
    2) it fetches column cust_name from table B via my new process and suppose to display it on page 7 as well. The problem is it doesn't display the value for cust_name. Why?
    My new process is of type PL/SQL anonymous block and its source is below:
    BEGIN
    SELECT name INTO :p7_cust_name
    FROM b
    WHERE pk_id = :p7_id;
    END;
    I get to page 7 by clicking an edit icon/link column on a row that is displayed on page 2 which is a report page. The link passes the pk_id value to page 7 for retrieve data for that row.

  • Concatenate columns from different Sql queries

    Hi ,
    I have two different queries on a same table with different conditions. I cant have these conditions in a single query as the result is not what is expected. But i have few common columns and I want the results of these queries next to the common columns. Below are the two different queries ..which I want the output to be concatenated in terms of columns :
    Query 1 :
    select * from
    ( select location,facility,floor,phase, seat_type,count(seat_type) abc from sa_master_table group by location,facility,floor,phase, seat_type order by location,facility,floor,phase, seat_type)
    pivot
    (sum(abc) for seat_type in ('Cabin','PL','Regular', 'Squeeze'))
    Query 2:
    select * from
    ( select location,facility,floor,phase, seat_type,count(seat_type) xyz from sa_master_table where employee = 'Vacant' group by location,facility,floor,phase, seat_type order by location,facility,floor,phase, seat_type)
    pivot
    (sum(xyz) for seat_type in ('Cabin','PL','Regular', 'Squeeze'))
    Hoping to find some solution for this..
    Thanks!

    Hi All,
    Thanks for your replies, but sorry for all the confusion. This is the first time I am in this pl/sql forum, so wasnt clear on providing the details.
    Ok.. Here are the details which I guess would be easier to understand my requirement :
    * I am working on Oracle Application Express 3.1 and this is where I want my query to be placed.
    * My previous post above has the exact query(s) which I am trying to format as below.
    Typical Output of the query is as below :
    h5. Location     Facility Floor     Phase     Cabin     PL      Regular     Squeeze
    Location1     Facility1 Floor1 Phase1 3 5 6 10
    Once I combine the results of these query, I want the output in the below format. And this is the requirement which I am looking at :
    h6. ************************************ |Total Allocated Seats     *******************|Vacant Seats
    h5. Location     Facility     Floor     Phase | Cabin     PL     Regular Squeeze |     Cabin PL     Regular Squeeze
    Location1     Facility1     Floor1 Phase1 | 3      5     6     10 | 1     0     2     3
    Location2     Facility2 Floor2 Phase2 | 2     6     10     3 | 0     2     1     4
    Query1 give the values of 'Total Allocated Seats' and Query2 gives the values of 'Vacant Seats'. Its basically appending the resultant columns of the queries which have the same columns but values are dependent on the conditions. I have 2 more queries which got to append after Vacant seats.
    I have tried using UNION , but it actually appends the values horizontally but I want them vertically as above.
    And as rightly told by Tk, Q2 is subset of Q1 and so would be other queries.
    I tried my best to have the format appear correctly.. but still its not aligned properly. In case of queries, please get back to me.Thanks!

  • Offset customer and vendor open items from different company codes

    Dear all,
    I would appreciate if you could help me with below issue:
    We have 2 company codes, these 2 company codes are under one company, i.e one group.
    When one company code (company code A) make vendor payment, the other company code (company code B) where this vendor is a customer and having Dr. balance, request company code A to deduct the amount receivable from B's customer, i.e vendor of company code A.
    Could it be possible to do this ín SAP?
    How to offset these two balances while running automatic payment F110?
    I would obliged any of your advise.
    Thank you very much.
    Rgds,
    Linh

    Hi,
    Please check following links
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/90f33e12-aeac-2a10-2186-ed8301f778ba?overridelayout=t…
    Cross company-code invoice posting and configuration - ERP Financials - SCN Wiki
    Regards,
    Tejas

  • HOW CAN I CREATE A VIEW FROM SAME TABLE WHERE I NEED COLUMNS DETAILS FROM DIFFERENT ROWS IN THE SAME TABLE

    i have a table1 on the top, but i want to create a view from table 1 as  view mentioned beneath the table 2. Could any of you please help me.
    table1
    ID
    office
    employee
    activity
    1
    246
    -9999
    698
    2
    ##-99
    21480
    698
    3
    104
    -9999
    7025
    4
    ##-99
    88908
    7025
    5
    108
    -9999
    2415
    6
    ##-99
    17135
    2415
    7
    246
    -9999
    698
    8
    ##-99
    21480
    698
    9
    104
    -9999
    7025
    10
    ##-99
    88908
    7025
    11
    108
    -9999
    2415
    12
    ##-99
    17135
    2415
    view
    ID
    office
    ID1
    employee
    activity
    1
    246
    2
    21480
    698
    3
    104
    4
    88908
    7025
    5
    108
    6
    17135
    2415
    7
    246
    8
    21480
    698
    9
    104
    10
    88908
    7025
    11
    108
    12
    17135
    2415

    declare @forumsTable table (ID int, officeID int, employeeID INT, activityID int)
    insert into @forumsTable (ID, officeID, employeeID, activityID)
    values
    (1 ,246, -9999, 698 ),
    (2 ,-99, 21480, 698 ),
    (3 ,104, -9999, 7025),
    (4 ,-99, 88908, 7025),
    (5 ,108, -9999, 2415),
    (6 ,-99, 17135, 2415),
    (7 ,246, -9999, 698 ),
    (8 ,-99, 21480, 698 ),
    (9 ,104, -9999, 7025),
    (10 ,-99, 88908, 7025),
    (11 ,108, -9999, 2415),
    (12 ,-99, 17135, 2415)
    select f1.ID, f1.officeID, f2.ID as ID1, f1.employeeID, f1.activityID
    from @forumsTable f1
    inner join @forumsTable f2
    on f1.activityID = f2.activityID
    and f1.officeID > 0
    and f2.employeeID > 0
    and f1.id - f2.id = -1
    You really need to improve the relationship here.
    Perhaps you could make office and activity an exclusive pair.

  • How to retrive latest items from different site collection using content search web part

    I have a web application that contains two site collections(team site + enterprise wiki), with the following URLs:-
    -http://applicationname/teamsite
    -http://applicationname/enterprisewik
    Now I need to display the latest 10 wiki pages that are inside the enterprise wiki site collection (according to the modified date) inside the team site. So I read that using Content search web part allows for cross-site content query.
    So I added a new content search web part , inside my team site, and I click on “change query” button. But I am not sure how I can reference the enterprise wiki site collection's library and to specify that I need to get the latest 10 wiki pages using the
    content search web part's query dialog box? Can anyone advice please ?
    Thanks

    Edit the webpart and click change query in search criteria.  click on switch to advanced mode and enter your path:
    (path:"http://applicationname/teamsite" OR path:"http://applicationname/enterprisewik")
    you can specify sorting by created date and click ok.  in number of items to show, type 10.  this should fulfill your requirement.
    For further reading, here are some links:
    http://office.microsoft.com/en-001/office365-sharepoint-online-enterprise-help/configure-a-content-search-web-part-in-sharepoint-HA104119042.aspx
    http://blogs.technet.com/b/tothesharepoint/archive/2013/04/30/stage-9-configure-the-
    query-in-a-content-search-web-part-on-a-category-page.aspx
    http://blogs.technet.com/b/tothesharepoint/archive/2013/05/23/stage-10-configure-the-query-in-a-content-search-web-part-on-a-catalog-item-page.aspx
    kashif

  • How to display additional items from an LOV?

    Hi guys,
    This is bound to be a fairly common scenario, though I didn't see it in the Forum archives. The wizard-based LOV facility provides support for one display value and one return value. But how do you display a half-dozen items from the row found in the LOV in addition to the one returned by the LOV?
    FWIW, here's what I came up with. I used the wizard-based LOV to bring back the first item. Then I added a button that said "Get additional values". An "After Submit" procedure, triggered by the new button, populates the other page items with values from the database table. Then in the "After Submit" Branches section, the same page is defined as the target page, again assuming that the new button was pushed. I figured that branch would render the new values. But no. From using the Session button, I can see that the additional page items are, indeed, populated correctly. But they don't become visible on the page. What gives?
    BTW, if there is a slicker/easier way to accomplish this, I'm all ears. Ideally, when the LOV returns its value, it would return all of the half-dozen additional values at the same time (no additional button to click). I look forward to your clever solutions.
    BTW, I'm using Apex 4.1 and Oracle 11g. Accomplishing this in server-side code is acceptable.
    Thanks much,
    Kim

    Thanks for the suggestion about the SkillBuilders Super LOV plug-in. I'm far from being an expert Apex developer, but I was able to install and use it very quickly. Now for the $64K question. I'm displaying a half-dozen or so columns in the LOV (which looks great). However, I'd like for every one of them to populate page items. That's the piece that I don't see how to accomplish. I read the documentation, but didn't see how to do it there. I'd very much appreciate it if you could tell me how to send those 6 LOV values to items in the page and have Apex display the values.
    Thanks so much,
    Kim

  • Rich Tree Table Drop duplicate Row Keys (from different Rich Tables)

    Hello.
    My scenario looks like this:
    Two tables (lets say productTable, and taskTable) as drag sources.
    One Tree Table ( that should have the productTable items as a parent node, and the childNodes would be taskTable items), as a drop target..
    In my test case, I was able to drag a row from a table, and drop it in a Tree Table. I could also program my drop listener in such a way that I could create child nodes. In my case I will only have 1 child node.
    - Parent Node 1
    - Child Node 1
    - Child node 2
    - Child node 3
    - Parent Node 2
    -Child node 4
    Example of my Tables
    Products
    prod1
    prod2
    prod3
    Tasks
    Task1
    Task2
    Task3
    Task4
    If I drag prod1 to the tree table, and then drag task1, to the treetable (on top of the prod1), I can't release the task1. The component will not accept this draggable item. If I drag any other task, other than task1, I can successfully insert this tag as a child node. I think it has something to do with the Row key. I'm using the dataFlavor as:
    <af:dataFlavor flavorClass="org.apache.myfaces.trinidad.model.RowKeySet"
    discriminant="ProductTaskModel"/>
    I think it has something to do with the row key, because if I drag prod2 to the treeTable and then try to put task2 in prod2 I get the same problem. I'm guessing that adf faces rc is generating the same row key for prod and task, and the tree table does not accept the same row key on top of the same row key.
    prod1 - rk=1
    prod2 - rk=2
    prod3 - rk=3
    task1 - rk=1
    task2 - rk=2
    task3 - rk=3
    Does anyone think it has something to do with this ?
    If it does, how can I generate different row keys ?
    Thanks a lot,
    John

    Hi,
    thanks for the testcase. I can reproduce the behavior. I found 2 minor issues in your code that I replied to you in a mail. I'll file a bug against the behavior. Should it turn out not to be a bug but a required coding change then I'll update this post
    Frank

Maybe you are looking for

  • Error COUNTRYGROUPING_NOT_FOUND

    Is some specific country grouping needs to be done for ESS ? We are implementing ESS and when we try to test some settings on portal the system is giving error saying "The following ABAP Exception occurred: COUNTRYGROUPING_NOT_FOUND". already assigne

  • Horizontal Scroll Bars

    HI, Here is my test page: http://hifiadd.com/test.html In IE Mac, I get a horizontal scroll bar on the bottom of the textfield div. I would imagine the same happens on PC? Any way to deal with this, or is this an unfortunate IE behavior? Thanks!

  • Appe TV synching, but not streaming

    I just got my Apple TV. It detects my network and the Apple TV icon appears on my devices in I-tunes. It synchs fine, but now the hard drive on the Apple TV is full and I hardly have any of my music on it. This thing is supposed to stream music and m

  • Deleting main adminin and trasfering its files to a new one

    I purchased a used macbook pro. Everything is great, i love it except the old user of this computer did not re-format the computer. The reason he didn't is because he has many nifty programs such as Final Cut Pro, PS, Ai, Id, DW and he wanted me to h

  • Two problem in screen and silent mood.

    Hi, I want to explain my problem and I hope to help me to solve this problem. I have Iphone device since 5 months ago and I have two problem. First, when I want to keep my Iphone at silent mood by move the button , the nope moves but the Iphone still