设个job自动去执行这个procedure,你的查询sql只管从那个view里面查就好了,select * from myresultviewtype值不确定的话,可以建一个procedure去动态根据type值执行,执行这个procedure生成一个view,再去查这个view就是根据当时type值所对应的结果: create or replace procedure p_mycolumn is v_sql varchar2(2000); cursor cursor_1 is select distinct t.type from temp t order by t.type; BEGIN v_sql := 'select name'; for v_temp in cursor_1 loop v_sql := v_sql || ',' || 'SUM(decode(type,''' || v_temp.type || ''',1,0)) AS ' || v_temp.type; end loop; v_sql := v_sql || ' from temp group by name order by name'; v_sql := 'create or replace view myresultview AS ' || v_sql; --DBMS_OUTPUT.PUT_LINE(v_sql); execute immediate v_sql; end;