Oracle 定時查詢資料插入新表中(job+預存程序)

來源:互聯網
上載者:User

標籤:acl   submit   char   sele   var   to_char   operation   dex   bsp   

create table EGMAS_COUNT_DATA
(
TIMES       date not null,
COUNT NUMBER(30) not null,
SYSTEM_NAME VARCHAR2(30) not null,
Operation_index VARCHAR2(30) not null
);
-- Add comments to the columns
comment on column EGMAS_COUNT_DATA.TIMES
is ‘日期‘;
comment on column EGMAS_COUNT_DATA.COUNT
is ‘統計量‘;
comment on column EGMAS_COUNT_DATA.SYSTEM_NAME
is ‘系統編碼‘;
comment on column EGMAS_COUNT_DATA.Operation_index
is ‘業務運營指標名稱‘;

預存程序:

create or replace procedure orderCount is

  begin

   

    insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)

    SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE ORDER_RESOURCE = ‘13‘

    AND to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘Android手機訂單量(港澳台)‘

    FROM dual;

    insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)

    SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE ORDER_RESOURCE = ‘14‘

    AND to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘IPHONE手機訂單量(港澳台)‘

    FROM dual;

    insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)

    SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE

    to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘速運通訂單量(港澳台)‘

    FROM dual;

    commit;

  end orderCount;

/

 

設定job執行時間:

         variable jobno number;

begin

  dbms_job.submit(:jobno,‘orderCount;‘, sysdate, ‘TRUNC(sysdate+1)+1/24‘);

end;

/

 

啟動job:

 

begin

dbms_job.run(44);

commit;

end;

/

 

查看job是否存在:

select job, next_date, next_sec, failures, broken from user_jobs;

 

Oracle 定時查詢資料插入新表中(job+預存程序)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.