學習筆記 oracle+procedure+job

來源:互聯網
上載者:User

   寫的是一個記錄大量資料量的一個日記伺服器: 其中涉及到一個表以後可能要記錄大量的資料,就考慮了用分表來記錄資料,

   寫了預存程序每天生產一張表,其中大量是在網上找的資料,自己整理了下。

 

 

 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 ;

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.