Table modification operation record

This script is to record table modification operation by job .
1.Create modification table
set serveroutput on
exec pkg_mod_tab_record.pro_crt_tab;
PKG_MOD_TAB_RECORD.sql

2.Insert data into modification table
exec pkg_mod_tab_record.pro_int_rec

3.Create job to insert record everyday
mod_tab_record_job.sql
mod_tab_record_job.sql

4.Display table modification record
--Display table history operation

  SELECT t.*,
         ROUND (ratio_to_report (tot_int) OVER () * 100, 2) ratio_int,
         ROUND (ratio_to_report (tot_upd) OVER () * 100, 2) ratio_upd,
         ROUND (ratio_to_report (tot_del) OVER () * 100, 2) ratio_del
    FROM (  SELECT table_owner,
                   table_name,
                   SUM (inserts) tot_int,
                   SUM (updates) tot_upd,
                   SUM (deletes) tot_del,
                   SUM (inserts + updates + deletes) tot_dml
              FROM TMP_MOD_RECORD
          GROUP BY table_owner, table_name) t
ORDER BY tot_dml DESC;

--Dispay top 5 table modification by date
  SELECT t.*,
         ROUND (ratio_to_report (tot_int) OVER () * 100, 2) ratio_int,
         ROUND (ratio_to_report (tot_upd) OVER () * 100, 2) ratio_upd,
         ROUND (ratio_to_report (tot_del) OVER () * 100, 2) ratio_del
    FROM (  SELECT table_owner,
                   table_name,
                   to_char(timestamp,'yyyy-mm-dd') time,
                   SUM (inserts) tot_int,
                   SUM (updates) tot_upd,
                   SUM (deletes) tot_del,
                   SUM (inserts + updates + deletes) tot_dml,
                   RANK () OVER (partition by table_owner ,to_char(timestamp,'yyyy-mm-dd') ORDER BY SUM (inserts + updates + deletes) DESC)
                      tot_dml_rank,
                   RANK () OVER (partition by table_owner ,to_char(timestamp,'yyyy-mm-dd') ORDER BY SUM (inserts) DESC) tot_int_rank,
                   RANK () OVER (partition by table_owner ,to_char(timestamp,'yyyy-mm-dd') ORDER BY SUM (updates) DESC) tot_upd_rank,
                   RANK () OVER (partition by table_owner ,to_char(timestamp,'yyyy-mm-dd') ORDER BY SUM (deletes) DESC) tot_del_rank
              FROM TMP_MOD_RECORD
          GROUP BY table_owner, table_name,to_char(timestamp,'yyyy-mm-dd')) t
   WHERE tot_dml_rank <= 5
ORDER BY tot_dml DESC;


请使用浏览器的分享功能分享到微信等