Return in only one row

Tuning de Banco, Tuning de SQL, Ferramentas de tuning
  

Poston Tue, 05 Apr 2011 10:34 am

Facebook friends, blame me please, I have a SQL query that this returning me 2 lines, i.e. 2 Description.
I need this query returns instead of 2 lines, only 1.
Example: select ProductName from product where familiaproduto = ' FAMILY ' result is = Produto01 Produto02 But I need return Produto01/Produto02 how do I do it?

Thank you
scandolara

Poston Tue, 05 Apr 2011 10:40 am

There are several threads on the Forum, search by result rows in column or something,
diegolenhardt
Location: Recife

Poston Tue, 05 Apr 2011 11:12 am

It searches for CROSSTAB viewtopic.php?t=1651
dr_gori
Location: Seattle, WA, USA

Poston Fri, 06 May 2011 8:57 pm

I believe a queried type below to solve: select product description1 || Product2 from table.
gustavosanmartin
Location: salvador - bahia

Poston Thu, 07 Jul 2011 9:57 am

Dude, I believe with select will be complicated, you can make a function with a cursor that fit the string the way you want to. Example:
Code: Select all
create or replace function conc_resultado(scondicao in varchar) return varchar2 is
  Result varchar2(32000);
  cursor c is
   select familia from produtos where familia = scondicao;
begin
    for r in c loop
       result := result ||'/'|| r.familia;
    end loop;
    return(Result);
end conc_resultado;
lmendes.cps
Location: Campinas - SP

Poston Fri, 15 Jul 2011 12:10 pm

I agree with Imendes.

In short you are wanting to transform rows into columns. Right?
The problem is that the lines grow to the extent that new records are inserted. Therefore, it needs to be something dynamic as the Imendes presented.
Search right here in the forum: how to turn rows into columns.

Hugs
sysdigo
Location: SP

Poston Fri, 15 Jul 2011 3:27 pm

Hello, check out this link and see if it helps.

http://www.dba-oracle.com/t_converting_rows_columns.htm

:-o
ishii
Location: São Paulo - SP


Poston Wed, 10 Aug 2011 8:27 pm

If you are using Oracle 11 g, use the analytic LISTAGG function. Heres the link http://www.oracle-base.com/articles/mis ... niques.php.

In my BD SQL tuning training at Oracle (10 g and 11 g) I teach how to use these functions. View http://www.fabioprado.net/p/treinamentos.html Att, Fabio Prado http://www.fabioprado.net
fbifabio
Location: São Paulo - SP


  • See also
    Replies
    Views
    Last Post


Return to DBA Tuning

Who is online

Users browsing this forum: No registered users and 2 guests