--计算每天的时平均气温
create or replace procedure TEMPERATUREAVGHOUR(CurrentDay in date)
is
    --声明游标,用于记录记载气温的测点编码
            cursor C_MCODE is select measurecode from pz_measurepoint,ZD_MEASUREPOITTYPE
                              where pz_measurepoint.mptypeid=ZD_MEASUREPOITTYPE.mptypeid and ZD_MEASUREPOITTYPE.mptypecode='02';
            v_mcode varchar(30);
            v_mtablename varchar(30);--构建出的测量表名
            v_stablename varchar(30);--构建出的统计表名
            v_insertsql varchar(1000);--动态语句
            v_wfcode char(4);--风场编码
            v_wttype char(2);--设备类型
            v_wtcode char(3);--设备编号
            v_AvgTemperature number(5,3);--平均温度
begin
            begin
            open C_MCODE;
            loop
            fetch C_MCODE into v_mcode;
            EXIT WHEN C_MCODE%NOTFOUND;
            /*
                v_mtablename:=''D_''||substr(v_mcode,1,7)||''_''||substr(v_mcode,12);
                --取出平均温度赋值给变量
                execute immediate 'select avg(value) from  '|| v_mtablename ||  
                                  'where to_char(recordtime, 'yyyy:mm:dd')= to_char(to_date('
                                  ||CurrentDay||', 'yyyy-mm-dd hh24:mi:ss'), 'yyyy:mm:dd')' into v_mtablename
                v_stablename:=''D_''||substr(v_mcode,17);
                v_wfcode:=substr(v_mcode,1,4);
                v_wttype:=substr(v_mcode,6,2);
                v_wtcode:=substr(v_mcode,8,3);
                --把计算好的数据插入到统计表中
                execute immediate 'insert into '||v_stablename||'(Seqid,Wfcode,Wttype,Wtcode,Cycle,Recordtime,Value,Quality)values(seq_'
                                  ||v_stablename||'.nextval,:v_wfcode,:v_wttype,:v_wtcode,1,sysdate,:v_mtablename,41)';
                                  */
            end loop;
            close C_MCODE;
            end;
end TEMPERATUREAVGHOUR

解决方案 »

  1.   

    end TEMPERATUREAVGHOUR;  后面要有一个分号
      

  2.   

    execute immediate 'select avg(value) from  '|| v_mtablename ||  
                                      'where to_char(recordtime, 'yyyy:mm:dd')= to_char(to_date(' 
                                      ||CurrentDay||', 'yyyy-mm-dd hh24:mi:ss'), 'yyyy:mm:dd')' into v_mtablename 
    改成
    execute immediate 'select avg(value) from  '|| v_mtablename ||  
                                      ' where to_char(recordtime, ''yyyy:mm:dd'')= to_char(to_date(' 
                                      ||CurrentDay||', ''yyyy-mm-dd hh24:mi:ss''), ''yyyy:mm:dd'')' into v_mtablename 
      

  3.   

    execute immediate 'insert into '||v_stablename||'(Seqid,Wfcode,Wttype,Wtcode,Cycle,Recordtime,Value,Quality)values(seq_' 
                                      ||v_stablename||'.nextval,:v_wfcode,:v_wttype,:v_wtcode,1,sysdate,:v_mtablename,41)'; 
    改成
    execute immediate 'insert into '||v_stablename||'(Seqid,Wfcode,Wttype,Wtcode,Cycle,Recordtime,Value,Quality)values(seq_' 
                                      ||v_stablename||'.nextval,v_wfcode,v_wttype,v_wtcode,1,sysdate,v_mtablename,41)'; 
      

  4.   

    v_mtablename:=''D_''||substr(v_mcode,1,7)||''_''||substr(v_mcode,12); 
    这个改成
    v_mtablename:='D_'||substr(v_mcode,1,7)||'_'||substr(v_mcode,12);