Q:

How to execute a multi row cursor as a table report

Dear friends i have done this:
    FUNCTION ALL_CLIENTS_DATA
    ( client_in IN varchar2)
    RETURN sys_refcursor
    IS c1 sys_refcursor;
    BEGIN
    OPEN c1 FOR
    Select TO_CHAR('SELECT '''||ATR_NOMBRE_ATRIBUTO||''','||ATR_VALOR_ATRIBUTO||' FROM '||ATR_VALOR_TABLA||' WHERE NRO_CLIENTE='''||client_in||''';')FROM GNT_ATRIBUTO WHERE ATR_TAB_IDENTIFICADOR = 7;
    RETURN c1;
    END;

And receiving this as cursor/function value:
    SELECT 'Estado',TO_CHAR(DECODE(estado,0,'ACTIVO',1,'ELIMINADO',2,'RETIRADO',3,'NUEVO',4,'PROCESO DE RETIRO','No Disponible')) FROM cliente WHERE NRO_CLIENTE='253417';
    SELECT 'SED-Cuadro-Llave',cadena FROM cliente WHERE NRO_CLIENTE='253417';
    SELECT 'Sector',to_char(sector) FROM cliente WHERE NRO_CLIENTE='253417';
    SELECT 'Zona',to_char(zona) FROM cliente WHERE NRO_CLIENTE='253417';
    .
    .
    .

And this if I execute line for line (alone for testing):
Estado  ACTIVO
SED-Cuadro-Llave    00100S / 21 / 3SP
Sector  89
Zona    291
.
.
.

I just don't know how to display my final result in a single execution. Please help.

A:

If you want all the attributes in one row you need to assemble a query from the result set of GNT_ATRIBUTO then open the cursor for that.
FUNCTION ALL_CLIENTS_DATA
    ( client_in IN varchar2)
    RETURN sys_refcursor
IS 
    stmt varchar2(32767);
    c1 sys_refcursor;
  l_tgt_table varchar2 (32767);
BEGIN
    stmt := 'select ';
    for lrec in ( 
        Select ATR_NOMBRE_ATRIBUTO
                , ATR_VALOR_ATRIBUTO
                , ATR_VALOR_TABLA
                , rownum as rn
        from GNT_ATRIBUTO 
        where ATR_TAB_IDENTIFICADOR = 7     
    )
    loop    
        if lrec.rn > 1 then
            stmt := stmt || ',';
        end if;
        stmt := stmt || lrec.ATR_VALOR_ATRIBUTO 
                     || ' as "' || lrec.ATR_NOMBRE_ATRIBUTO || '"';
    l_tgt_table := lrec.ATR_VALOR_TABLA;
    end loop;
    stmt := stmt || ' from ' || l_tgt_table
                 || ' WHERE NRO_CLIENTE= :p1 ';
    OPEN c1 FOR stmt using client_in;
    RETURN c1;
END;

