統(tǒng)計(jì)不固定欄目的工資年報(bào)的存儲(chǔ)過(guò)程

字號(hào):

v_lmmc varchar2(20);--欄目名稱
    v_sql varchar2(1000);
    --定義取工資欄目的游標(biāo)
    cursor cur_lmmc is
    select distinct lmmc
    FROM tmp_gztjlsb;
    begin
     --定義動(dòng)態(tài)SQL
     v_sql:=@#select rydm,xm@#;
     --遍歷工資欄目并拼寫成插入的SQL
     for cur_lmmc_rec in cur_lmmc loop
     v_lmmc:=cur_lmmc_rec.lmmc;
     v_sql:=v_sql||@#,@#||@#sum(decode(lmmc@#||@#,@#@#@#||v_lmmc||@#@#@#,je))@#||@# @#||v_lmmc;
     end loop;
     v_sql:=v_sql||@# from tmp_gztjlsb group by rydm,xm@#;
     execute immediate @#insert into @#||p_table||@# @#||v_sql;
     commit;
    end prc_rs_gzndbb;