Function to concatenate all query results in a single row comma separeted

Hi All,
my version is Oracle 10.2.0.4.0
this is my query:
select distinct
table1.id
from table1,
table2,
table3
where table1.id = table2.id
and table2.id = table3.id
and table3.id = '761'
and result is:
61
18
68B
S05
S18
68
could someone provide me a function (or something else) in order to have a result like this:
61,18,68B,S05,S18,68
and call it from another query?
I appreciate your help.
Many thanks.
Alessandro

user12889282 wrote:
could someone provide me a function (or something else) in order to have a result like this:
61,18,68B,S05,S18,68
and call it from another query?But this is the wrong way to do it. Better use the original query as a subquery for your second query.
let me demonstrate it
select *
from someotherTable x
where x.FK_ID IN (select t1.id
          from table1 t1
          table2 t2,
          table3 t3
          where t1.id = t2.id
          and t2.id = t3.id
          and t3.id = 761 /* use numbers not strings for IDs! */
;Edited by: Sven W. on Jul 30, 2010 10:17 AM

Similar Messages

  • I need to print one query result as a single row

    Hi,
    I need to print one query result as a single row ,which gives more than one value (of subinventories)and also i would like to print the quantity of that particular subinventory at particular place.Please suggest how can i do this in the report builder?

    Actually I need to print inventory report with subinventory break up.For that all subinventories of category code AB are taken as single row.Based on that subinventory value Quantity must be printed at that particular place.
    For ex
    Quantity
    Item no Description Subinventory Code AB_Abc AB_Def AB_ghi
    1 ***** 12 9
    2 ****** 8 5
    like that.I am waiting for the reply.Plz its some how urgent.
    Thank you,

  • Template:Multiple field result in a single row, comma separated

    Hello,
    without* having to write a function in Pl/SQL, is it possible, when I have this query,
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = 'FIGARO'**Instead of having this result ( with break in the template)*
    FIGARO    C2008-203   12l10201.tif
                        12l10202.tif
                        12l11101.tif
                        12l11102.tif
                        12l11201.tif
                        12l11202.tif
                        12l12101.tif
                        12l12102.tif
              C2008-204     12l12202.tif
                        12l13101.tif
                        12l13102.tif
                        12l13201.tif
                        12l13202.tif
                        12l14101.tif
                        12l14102.tif
                        12l14201.tif
                        12l14202.tif
                        12l15101.tif
                        12l15102.tif
                        12l15201.tif
                    C2008-205     12l15202.tif
                        12l16101.tif
                        12l16102.tif
                        12l16201.tif
                        12l16202.tif
                        12m01101.tif
                        12m01102.tifhaving this result, WITH the element only, comma separeted??? ( I can have from 0 to 500 elements)
    FIGARO
    DVD:        C2008-203
    Elements:  12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif, 2l11202.tif, 12l12101.tif, 12l12102.tifthanks, Roseline

    This should help you http://tkyte.blogspot.com/2007/03/stringing-them-up.html

  • How to display a 1 to many query result in a single row?

    Hi,
    I want to display a 1 to many relationship in a query in just one row. The current result is that I get more than 1 rows. How can I display it in one column with the additional attribute in a column, without repeating? Thank you.
    Select s.student, t.teacher from student_table s, teacher_table t where s.id = t.student_id
    Result
    Student Teacher
    John Doe Larry Woe
    John Doe Mary Moe
    I would rather get a result like this:
    Result
    Student Teacher 1 Teacher 2
    John Doe Larry Woe Mary Woe
    Edited by: Samantha on May 18, 2011 2:48 PM

    Hi,
    Will all Students have exactly two Teachers?
    If not picture your sample with two more Students.
    One having 1 Teacher
    One having N Teachers
    Think about N, what will it be? - How would you create a table with N columns?
    If you can't easily answer above, re-consider what you are trying.
    That said, it could still be done - even if all Students do not have exactly two Teachers - and is called Pivot a dynamic number of columns.
    Examples are in FAQ
    SQL and PL/SQL FAQ
    Still a bad idea, with or without known number of teachers
    Regards
    Peter

  • Is there a way to combine their query results into a single function

    say I have a bunch of functions that return a query:
    <cffunction name="getDeals" access="remote"
    returntype="query">
    <cffunction name="getDeals2" access="remote"
    returntype="query">
    is there a way to combine their query results into a single
    function that returns a struct of the various results?

    Umm, it's probably more suited to an array - effectively
    making it into a list of queries. You'd then loop the array and
    output each.
    I use a similar approach when creating system messages to the
    user. Most of my functions that are called do their bit, then at
    the end call another function I call "messages". This function
    grabs whatever my function sends and appends it to a messages
    array.
    This way enables me to output a long list of messages -
    because I could be calling several functions at the same time. If I
    just output a message from each function, each one would overwrite
    the other. So I'd get one message at a time.
    Immediately after it's output, I then destroy the message
    array so that old messages aren't kept inside of it.
    Mikey.

  • Query results:every other record/row grey and white

    Hello guys,
    query results:every other record/row grey and white
    how would you make every other record/rows a different color
    just like the forums color. Lightest grey and white?
    <cfquery name="Myqueryname"
    datasource="#Request.MainDSN#">
    SELECT
    CompanyID,
    CompanyName,
    Address,
    City,
    State,
    ZipCode,
    Comments
    FROM
    Company
    ORDER BY
    CompanyName ASC
    </cfquery>
    <html>
    <head>
    <title>CF TUTORIALS</title>
    <link rel="stylesheet" href="styles.css">
    </head>
    <body>
    <h1>All CO Listings</h1>
    <table>
    <tr>
    <td><b>ID</b></td>
    <td><b>Name</b></td>
    <td><b>Address</b></td>
    <td><b>City</b></td>
    <td><b>State</b></td>
    <td><b>ZIP Code</b></td>
    <td> </td>
    </tr>
    <cfoutput query="Myqueryname">
    <tr>
    <td>#CompanyID#</td>
    <td>#CompanyName#</td>
    <td>#Address#</td>
    <td>#City#</td>
    <td>#State#</td>
    <td>#ZipCode#</td>
    <td>
    <a href=" ALL Emps.cfm?CompanyID=#CompanyID#">ALL
    Emps</a>
    <a href=" AddCO Form.cfm">AddCO</a>
    <a href="
    Editco.cfm?CompanyID=#CompanyID#">Editco</a>
    <a
    href="CoDeleteForm.cfm?CompanyID=#CompanyID#">Delete</a>
    </td>
    </tr>
    </cfoutput>
    </table>
    </body>
    </html>

    There is a cool tool in Coldfusion called MOD
    This basically calculates the remainder of the row number
    when divided.
    I interpreted its use to something like this, which has
    worked for me.
    <cfoutput query="qry_requestedlist" maxrows="30"
    startrow="1">
    <cfset EvenRow=#CurrentRow# +1>
    <cfif CurrentRow Mod 2 IS 1>
    <tr>
    <th class="grey" CurrentRow#</th>
    <cfelse>
    <th class="white">#CurrentRow#</th>
    <tr>
    </cfif>
    </cfoutput>
    I doubt this is precisely what you want but this is the sort
    of thing.

  • SQ01 results in a single row

    Hi Gurus,
    I have been using the sq01 query to do complex calculations and have been successful in creating tons of queries. What I am stuck with right now is this situation. I created a query and the result is in multiple rows. Here's what it looks like
    Col1      Col2                 Col3             Col4           Col5
    0014       0.00               12.00             0.00           1.00
    0014     20080428           0.00             0.00            0.00
    0014        0.00                0.00             5.00            0.00
    0014        0.00                0.00             0.00            0.00
    Here;s what I want it to look like
    Col1      Col2          Col3       Col4     Col5
    0014     20080428   12.00      5.00     1.00
    Which means i dont want any rows that basically have 0.00 throught and for the key 0014 I want all the data on one single row.
    Is there anyway we can do it using sq01.
    Any suggestions will be appreciated. Thanks in advance
    Kavita
    Edited by: Kavita on Feb 18, 2009 7:44 PM

    Hi,
    Its not possible to have in single row.
    this is same like Education infotype ,all the qualifications will show in different rows.
    You wont get it in single row.
    Bu try to Check Qucikviewer and join conditions...that might helpful to get it...

  • Trouble outputting all query results

    For some reason this code doesn`t output all the results only
    the first one. How can I can it working I did try a way that output
    all the results the same amount of times as there are Referer
    entries in the db which is obviously not what I want. What is the
    way to do thisso that it is cfoutput right? Thank you very much
    <cfquery name="qrysales">
    SELECT Referer
    FROM clientinfo
    </cfquery>
    <cfoutput><cfif len(qrysales.Referer)>
    <cfif find("?", qrysales.Referer)>
    <cfset paramList = "q,p,terms,search,query,qkw">
    <cfset strStart = find("?", qrysales.Referer)>
    <cfset referer_queryString =
    right(Referer,len(qrysales.Referer)-strStart)>
    <cfset referer_url =
    left(qrysales.Referer,(strStart-1))>
    <cfloop list="#referer_queryString#" delimiters="&"
    index="i">
    <cfif listfind(paramList,listfirst(i,"="))>
    <cfset variables.searchPhrase = listlast(i,"=")>
    </cfif>
    </cfloop>
    </cfif>
    </cfif>
    <cfif isdefined("variables.searchPhrase")>
    <cfoutput>#variables.searchPhrase#</cfoutput>
    </cfif>
    </cfoutput>

    The code works fine using the querynew values. When I use the
    db cfquery then I get the results output over and over again. Why
    is that?! Thanks
    <!---
    <cfquery name="qrysales">
    SELECT Referer
    FROM clientinfo
    </cfquery>--->
    <h3>QueryNew Example</h3>
    <cfset qrysales = QueryNew("referer")>
    <!--- make some rows in the query --->
    <cfset newRow = QueryAddRow(qrysales, 4)>
    <!--- set the cells in the query --->
    <cfset temp = QuerySetCell(qrysales, "referer", "
    http://search.live.com/results.aspx?q=environment+property+study&FORM=SSRE2
    ", 1)>
    <cfset temp = QuerySetCell(qrysales, "referer", "
    http://search.live.com/results.aspx?q=healthcare&mrt=en-us&FORM=LIVSOP",
    2)>
    <cfset temp = QuerySetCell(qrysales, "referer", "
    http://www.google.co.uk/search?q=grande+rio&sourceid=navclient-ff&ie=UTF-8&rlz=1B2GGFB_enG B251",
    3)>
    <cfset temp = QuerySetCell(qrysales, "referer", "
    http://www.google.de/search?q=Rio-Grande&ndsp=20&hl=de&ie=UTF-8&oe=ISO-8859-1&start=30&sa= N",
    4)>
    <cfoutput query="qrysales"><cfif len(#Referer#)>
    <cfif find("?", #Referer#)>
    <cfset paramList = "q,p,terms,search,query,qkw">
    <cfset strStart = find("?", #Referer#)>
    <cfset referer_queryString =
    right(Referer,len(#Referer#)-strStart)>
    <cfset referer_url = left(#Referer#,(strStart-1))>
    <cfloop list="#referer_queryString#" delimiters="&"
    index="i">
    <cfif listfind(paramList,listfirst(i,"="))>
    <cfset variables.searchPhrase = listlast(i,"=")>
    </cfif>
    </cfloop>
    </cfif>
    </cfif>
    <cfif isdefined("variables.searchPhrase")>
    #variables.searchPhrase#
    </cfif>
    </cfoutput>

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • Query results more than 200 rows.

    Hi all:
    I have a problem with a query that results more than 200 rows.
    Only show in a table 201 rows and warning about this message: "Query has exceeded 200 rows. Potentially more rows exist, please restrict your query."
    Is possible that the query show all results ???
    thanks!

    Its still a warning. You can continue with work but definitely you can increase the value through the profile value. Anything within 500 wouldn't cause much performance issue.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                   

  • How to set query result to a single window

    I am using SQL Developer 2.1063, and not happy with the default setting of result window. Everytimes when I run a query, the result appear in a new result window. Over a couple of hour I have tense or hundreds of result tabs in the low window. It is not quite fun to remove them one by one.
    I am sure it can be set so that all result appear in one result window, as I am used to in the old SQ Developer version. But I failed to find it in Prefernces and in Help.

    -K- wrote:
    This is fixed in the available 2.1.1.
    Have fun,
    K. K
    I've just tested on 2.1.1 and i came to the same conclusion as user10369687
    - if you check the box for "Preferences - Database - Worksheet - Automatically Freeze Result Tabs" or click the pin button or run as script (F5) or highlight the sql and run as script (F5) you always get new query result tab.
    The option name suggest that if you check the box the same result tab will be used for different queries which is not true, is the oposite way.
    If the option name is changed than the confusion will be cleared.
    Dani

  • Query - Purchasing information in single row

    Hi Experts,
    I have a requirement to create a report which shows products with all POs in a single row.    In many cases we will have several open PO at one time for the same product.   For example - item SUFF2231-M will have:
    PO
    Qty
    Due Date
    42771
    200
    10/05/2014
    42883
    250
    20/05/2014
    43321
    150
    30/05/2014
    43375
    100
    10/06/2014
    43401
    100
    20/06/2014
    We only need to see up to 5 PO for each product.   Ideally I need to be read them on a single line like so:
    ItemCode
    PO1
    Qty1
    DueDate1
    PO2
    Qty2
    DueDate2
    PO3
    Qty3
    DueDate3
    PO4
    Qty4
    DueDate4
    PO5
    Qty5
    DueDate5
    SUFF2231-M
    42771
    200
    10/05/2014
    42883
    250
    20/05/2014
    43321
    150
    30/05/2014
    43375
    100
    10/06/2014
    43401
    100
    20/06/2014
    Is this possibe using only SQL query?
    Regards
    Geoff

    Hi Geoff,
    You can use the ROW_NUMBER and CASE Functions to acheive this. Here with , i have give u a small idea with an ex:
    Qry :
    B.ItemCode,SUM(B.PO1)[PO1],SUM(B.POQty1)[POQty1],SUM(B.PO2)[PO2],SUM(B.POQty2)[POQty2] From
    select Itemcode
    CASE when Sno=1 Then DocNum End [PO1]
    CASE When Sno=1 Then Qty End [POQty1]
    CASE when Sno=2 Then DocNum End [PO2]
    CASE When Sno=2 Then Qty End [POQty2]
    From(
    Row_Number() Over (Order By Opor.Docnum) [Sno], Opor.DocNum,POr1.ItemCode,sum(POr1.Quantity)[Qty] from OPOR join Por1 on Opor.DocEntry=por1.DocEntry
    ItemCode='20002' group by oPor.DocNum,por1.ItemCode
    A where A.Sno<=2)B Group By B.ItemCode
    Result :-
    ItemCode  PO1         POQty1           PO2            POQty2
    20002       18            1.000000         19                10.000000
    Thanks,
    Karthikeyan.P

  • Merging two results into a single row

    Hi, Everyone... I think this is a weighted question and I feel like it's a bit difficult to phrase, so if it doesn't make sense - let me know and I'll try to clarify or provide some more concrete examples (if I can) :)
    I have a few tables inner joined in my sql query - I'd post the entire query here but it's lengthy and will probably add a bit more confusion so let's start with theorizing - where the results sometimes generate more than one row. If more than one row exists, I'd like to take the lowest number in one field and the highest number in another field, and display them on a single row.
    For instance, when I join the PERIOD and SCHEDULE tables, the PERIOD table might provide two rows like the following:
    SCHEDULE_ID      PERIOD_ID      START_TIME    END_TIME
    123               100           32820          35640
    123               101           35940          38760My final result should take the lowest START_TIME and the highest END_TIME, even if they exist is separate rows.
    START_TIME     END_TIME
    32820           38760It doesn't seem easy to me so if someone can make sense of this - you deserve an award. :) If I can provide some more clarification, please let me know. Thanks for any help. Oracle 11g
    Edited by: nage62587 on Sep 27, 2012 11:32 AM

    nage62587 wrote:
    Thanks! I'll try that... I have more than these columns in the result and I'm thinking a Group By likely wouldn't work - I will try but in the event it doesn't, does anyone else have any other suggestions?Group by is the correct way to do this. You group several rows of output into one row. Then you decide which values from inside that group you want to see. This is certainly possible. There are more aggregation functions available than you might think, not only min/max, also min/max + KEEP, count(case expression) and so on.

  • Returning results as a single-row sub query.

    Hi,
    This is my current query
    WITH car as (SELECT 'FORD' make FROM DUAL UNION SELECT 'TOYOTA' make FROM DUAL UNION SELECT'BMW' make FROM DUAL UNION SELECT 'FIAT' make FROM DUAL)
    SELECT * FROM CARWhich returns:-
    BMW
    FIAT
    FORD
    TOYOTAHowever the actual output required:-
    'BMW, FIAT, FORD, TOYOTA'i.e. all returned on one row.
    Any ideas on how to do this??
    Thanks in advance!
    David

    Hi,
    Or: use row_number() and connect by:
    SQL>  select ltrim(sys_connect_by_path(make,', '),', ') make
      2   from  (
      3         WITH car as (SELECT 'FORD' make FROM DUAL union
      4                       SELECT 'TOYOTA' make FROM DUAL UNION
      5                       SELECT'BMW' make FROM DUAL UNION
      6                       SELECT 'FIAT' make FROM DUAL
      7                      )
      8         SELECT make
      9         ,      row_number() over (order by make) rn
    10         FROM CAR
    11         )
    12    where connect_by_isleaf = 1
    13   connect by rn = prior rn + 1
    14   start with rn = 1
    15   order by make
    16  ;
    MAKE
    BMW, FIAT, FORD, TOYOTA
    1 row selected.Edited by: hoek on Jun 5, 2009 12:56 PM
    But how could I even think I'd type faster than Lightnin' Blushadow? ;)

  • How to concatenate all the fields in a single statement with tilda..

    hi, i have 10 fields, i have to concatenate those fields seperated with tilda... and put into the application server...in a single statement,
    kindly suggest me hw to write..?
    Thanx in Advance.
    Akshitha.

    Hi.....
    Just see the following code...
    It solves your requirement.....
    REPORT  ZCSV_SPFLI_APP.
    TABLES :
      SPFLI.                               " Flight
      FIELD-SYMBOLS : <FS>. "TYPE C.
    DATA T_SPFLI LIKE STANDARD TABLE OF SPFLI .
    DATA W_CHAR(20) TYPE C.
    DATA W_TYPE .
    DATA:
      BEGIN OF T_TABLE OCCURS 0,
        LINE TYPE STRING,
      END OF T_TABLE.
    SELECT * FROM SPFLI INTO TABLE T_SPFLI.
    LOOP AT T_SPFLI INTO SPFLI.
      DO.
        ASSIGN COMPONENT SY-INDEX OF STRUCTURE SPFLI TO <FS>.
        IF SY-SUBRC NE 0.
          EXIT.
        ELSE.
          MOVE <FS> TO W_CHAR.
          IF SY-INDEX EQ 1.
            T_TABLE-LINE = <FS>.
          ELSE.
            CONCATENATE T_TABLE-LINE '~' W_CHAR INTO T_TABLE-LINE.
          ENDIF.
        ENDIF.
      ENDDO.
      CONDENSE T_TABLE-LINE.
      APPEND T_TABLE.
    ENDLOOP.
    LOOP AT T_TABLE.
      WRITE / T_TABLE-LINE.
    ENDLOOP.
    OPEN DATASET 'YH647_SPFLI' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF SY-SUBRC NE 0.
      MESSAGE ' File is Not Opend' TYPE 'S'.
    ENDIF.
    LOOP AT T_TABLE.
      TRANSFER T_TABLE-LINE TO 'YH647_SPFLI'.
    ENDLOOP.
    CLOSE DATASET 'YH647_SPFLI'.
    This reads flight detail and makes the separated by '~' and  stores in the application server (<b>OPEN_DATASET, TRANAFER , CLOSE DATASET</b>)
    Reward points if useful.........
    Suresh........

Maybe you are looking for