我现在做的项目 有一张表 我要统计每年每个月和每天产生的金额总量从而插到中间表,因为每天都用数据传送上来  所以要计算
     请问用存储过程怎么样出写   求各位大神指教!

解决方案 »

  1.   

    不是 我这是想知道大概的思路 
    create or replace procedure P_BANKSUM is
    sqls varchar(2000);
    begin
      delete from gzjg_banksum;
      for rsUnit in (select unit_id, unit_prop15 from iufo_unit_info where pk_parent = 'GDSHJGQY900000000000') loop
        for rsAccount in (select bankacc_pk, banktype,unitid from gzjg_bankaccbas where banktype <>'01' and unitid in ( select unit_id from iufo_unit_info o where substr(unit_code,0,12)=( select unit_code from iufo_unit_info where unit_id= rsUnit.unit_id)) and ACCOPENDATE <= to_char(sysdate - 1, 'yyyy-mm-dd') and not banktype is null) loop
          for rsBalance in (select avg(balancelocal) balancelocal from gzjg_accbalance where bankacc_pk = rsAccount.bankacc_pk and balancedate = (select max(balancedate) from gzjg_accbalance where unitid = rsAccount.Unitid and bankacc_pk = rsAccount.bankacc_pk)) loop
            --insert into ... values(rsUnit.unit_id, rsAccount.banktype, rsAccount,bankacc_pk, rsBalance.balancelocal)
            --DBMS_OUTPUT.PUT_LINE(rsUnit.unit_id || ' - ' || rsAccount.banktype || ' - ' || rsAccount.bankacc_pk || ' - ' || rsBalance.balancelocal);
            sqls := 'insert into gzjg_banksum values(''' || rsUnit.unit_id || ''',''' || rsAccount.banktype || ''',''' || rsAccount.bankacc_pk || ''',''' || rsBalance.balancelocal || ''')';
            execute immediate sqls;
          end loop; --rsBalance
        end loop; --rsAccount
      end loop; --rsUnit
      commit;
    这个是我们之前写的一个  统计前一天的数据  金额的总数
       现在他我写一个 统计每天每月每年的 所以我想知道是怎么统计就好了  谢谢