Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> problem with creating a view translating rows to columns

problem with creating a view translating rows to columns

From: Dot <dj_bodle_at_yahoo.co.uk>
Date: 16 Aug 2006 08:45:46 -0700
Message-ID: <1155743146.288214.153340@74g2000cwt.googlegroups.com>


Hi

I have created a view using a procedure as below

procedure HTS_VIEW_RESULT_HOR
  as

    cursor decodes is

        select unique result_type,type_desc,data_type from hts_result_type where data_type !='S';

    cursor charres is

        select unique result_type,type_desc,data_type from hts_result_type where data_type ='S';

    sqltxt VARCHAR2(32767);

   BEGIN

--add decode statements for result types

      for aline in decodes loop
         sqltxt := sqltxt ||

'decode(r.result_type,'||aline.result_type||',r.result_value,NULL)'||UPPER(translate((replace(replace(aline.type_desc,'%','Percent
'),'#','')), ' /!£$^&*()-+=[]{}@~:;?">.,<|\', '_'))||', ';

      END LOOP;  --add decode statements for result types

      for bline in charres loop
         sqltxt := sqltxt ||

'decode(r.result_type,'||bline.result_type||',r.result_val_char,NULL)'||UPPER(translate((replace(replace(bline.type_desc,'%','Percent
'),'#','')), ' /!£$^&*()-+=[]{}@~:;?">.,<|\', '_'))||', ';

      END LOOP;

dbms_output.put_line('SQL just before execute: ' ||sqltxt);

      EXECUTE IMMEDIATE sqltxt;

      sqltxt := 'grant select on hts_view_result_hor to hts_user';
      EXECUTE IMMEDIATE sqltxt;

      sqltxt := 'create or replace public synonym hts_view_result_hor
for hts_view_result_hor';
      EXECUTE IMMEDIATE sqltxt;

   END; This works fine however I have one problem with this it creates my view like below

sample_id test1 test2 test3

1          1
1                  1.25
1                        0.23
2                  1.25
3          34
3                         67

But what I really want is

sample_id test1 test2 test3

1          1      1.25    0.23
2                 1.25
3          34             67

I know if I only do the decode part of the view creation script then I would get this but Iwould not get the other information that I need.

As I am running in 9i and can not for the foreseable future upgrade to V10 I can not use rowtocol.

any suggestions greatly appreciated.

Dot. Received on Wed Aug 16 2006 - 10:45:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US