日期:2014-05-16 浏览次数:20491 次
select quarter ,sum(decode(name,'开发部',quantity,0)) 开发部, sum(decode(name,'销售部',quantity,0)) 销售部 from department group by quarter
declare cv_sql varchar2(5000):=' '; cn_number number; cn_i number :=0; sql_query varchar2(5000); begin for v_cur in (select distinct name into cn_number from department) loop cv_sql:= cv_sql||',sum(decode(name,'''|| v_cur.name ||''',quantity,0)) '|| v_cur.name; end loop; sql_query:='create or replace view query_zjx_v as select quarter'||cv_sql||' from department group by quarter'; dbms_output.put_line(sql_query); execute immediate sql_query; end;