Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a single column of rows in one cell

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
If I have the SQL statement
Code:
SELECT
dsti_proj_ref
FROM
odf_ca_project

how can I have each row of this in one cell.

lets say the results of the above query returns 5 rows:

Code:
Proj123
Proj345
Proj456
Proj567
Proj678

how can I write a select statement to give me:
Code:
Proj123Proj345Proj456Proj567Proj678
is this possible?

thanks in advance
 
(Turbo, Didn't we do something else with the "odf_ca_project" table on April 25 of this year?)

In any case, there are multiple methods...some easier than others. The easiest method is with a user-defined function.

Tell us more about your scenario:

1) Since your code, above has no WHERE clause, I presume that you want all row instances of "dsti_proj_ref"
from the "odf_ca_project" table, correct?

2) If so, is the number of rows in "odf_ca_project" static?

If not on Item #2, then, by far, your best method of achieving your objective is to build a function. And even if the number of rows is static, your best bet is a user-defined function such as
Code:
create or replace function get_dsti_proj_ref return varchar2 is
    hold_result varchar2(4000);
begin
    for r in (SELECT dsti_proj_ref from odf_ca_project) loop
        hold_result := hold_result||r.dsti_proj_ref;
    end loop;
    return hold_result;
end;
/

Function created.

Then, you can invoke that function to achieve your results:
Code:
SELECT get_dsti_proj_ref from dual;

GET_DSTI_PROJ_REF
-----------------------------------
Proj123Proj345Proj456Proj567Proj678
Let us know if this resolves your need.




[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top