此处不能使用分组函数 oracle
CREATE OR REPLACE PROCEDURE DBB01_1_MONTH_LOSS_date(P_rq varchar2,P_Filed varchar2) is
--------date 2013-12-12
-------for Monthly Loss Analysis
begin
declare
exist_num number(12);
exist_time varchar2(12,2);
exist_oil number(12,4);
cursor C_existdm is
select * from (select b.mc ,a.* from dba01 a,v_dab913_fpf_station b where substr(a.jhdm,0,6)=b. station ) y
where y.gjdm is not null and to_char(y.rq,'yyyymm')=P_rq and y.mc=P_Filed;
Y_existdm C_existdm%type;
begin
for Y_existdm in C_existdm loop
select count(*) into exist_num,round(sum(24-y.scsj),2) into exist_time,round(sum(y.lyrcyl),4) into exist_oil
from (select b.mc ,a.* from dba01 a,v_dab913_fpf_station b where substr(a.jhdm,0,6)=b. station ) y
where y.gjdm is not null and to_char(y.rq,'yyyymm')=P_rq and y.mc=P_Filed group by Y_existdm.gjdm;
end loop;
end;
end DBB01_1_MONTH_LOSS_date;
各位大仙帮我看看,编译的时候报这个错PROCEDURE DPOC1208.DBB01_1_MONTH_LOSS_DATE 编译错误 PL/SQL: ORA-00934: group function is not allowed here,小弟先谢过了
------解决方案--------------------你这group by 个游标的值 有什么用呢
------解决方案--------------------你上面写了一个游标,下面就用这个游标做一个group by, 想不通。。。
你的目的是把
select count(*) into exist_num,round(sum(24-y.scsj),2) into exist_time,round(sum(y.lyrcyl),4) into exist_oil
from (select b.mc ,a.* from dba01 a,v_dab913_fpf_station b where substr(a.jhdm,0,6)=b. station ) y
where y.gjdm is not null and to_char(y.rq,'yyyymm')=P_rq and y.mc=P_Filed
这个SQL的结果插到一个表里,正常的逻辑是你在游标里面得到你要的这个结果,然后再循环插到目标表里。
楼上已经说了。
目测你的SQL,这个结果是聚合函数的结果,只有一个结果,你用游标,只能循环一次,游标显得多余。
还是那句话, 你在游标里面该聚合的聚合,该分组的分组,得到你要的结果后,再insert 到你的target表里。