寫的是一個記錄大量資料量的一個日記伺服器: 其中涉及到一個表以後可能要記錄大量的資料,就考慮了用分表來記錄資料,
寫了預存程序每天生產一張表,其中大量是在網上找的資料,自己整理了下。
create or replace procedure createlogs_time
Authid Current_User
as
tabname varchar(200);
begin
select 'ex_log' || to_char(sysdate, 'yyyymmdd') into tabname from dual;
--create table tabname as select * from tbl_programme where 1 != 1;
execute immediate 'create table ' || tabname ||' tablespace manage as select * from TMON_MONITOR_LOG_EXCLOG where 1 != 1';
commit;
end;
job是讓這個預存程序每天的晚上八點執行
variable job2 number ;
begin
dbms_job.submit(:job2,'createlogs_time;',trunc(sysdate+)+20/24,'trunc(sysdate+)+20/24');
commit;
end ;
然後要把每天生產的這張表的一些資訊統計 寫了預存程序
create or replace procedure updateC is
type rc is ref cursor;
l_cursor rc;
v_sql varchar2(1000);
v_tab_name varchar2(30);
times varchar(20);
log_time varchar(40);
res_name varchar(40);
res_req_times varchar(40);
begin
select to_char(sysdate, 'yyyymmdd') into times from dual;
select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') into log_time from dual;
--v_tab_name := 'ex_log20090828';
select 'ex_log' || to_char(sysdate,'yyyymmdd') into v_tab_name from dual;
v_sql:= 'select res_name, count(req_type) as resSum from ' || v_tab_name || ' where req_type=''finish'' group by res_name';
open l_cursor for v_sql;
loop
fetch l_cursor into res_name,res_req_times;
exit when l_cursor%notfound;
insert into TMON_monitor_count_exlog values(test.nextval,times, res_name, log_time,res_req_times,res_req_times);
end loop;
close l_cursor ;
end;
job每天晚上的八點執行這個預存程序
variable job2 number ;
begin
dbms_job.submit(:job2,'updateC;',trunc(sysdate+)+20/24,'trunc(sysdate+)+20/24'); commit;
end ;