Oracle timed query data is inserted into a new table (job+ stored procedure)

Source: Internet
Author: User

CREATE TABLE Egmas_count_data
(
Times date NOT NULL,
COUNT number (+) is not NULL,
System_name VARCHAR2 (+) NOT NULL,
Operation_index VARCHAR2 (+) NOT NULL
);
--ADD comments to the columns
Comment on column egmas_count_data. Times
is ' date ';
Comment on column egmas_count_data. COUNT
is ' statistic ';
Comment on column egmas_count_data. System_name
Is ' system code ';
Comment on column egmas_count_data. Operation_index
Is ' Business operation indicator name ';

Stored procedures:

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 Phone order volume (Hong Kong, Macao and Taiwan) '

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 order volume (Hong Kong, Macao and Taiwan) '

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 ', ' Speed Express order Volume (Hong Kong, Macao and Taiwan) '

from dual;

Commit

End OrderCount;

/

Set Job execution Time:

Variable jobno number;

Begin

Dbms_job.submit (: Jobno, ' ordercount; ', Sysdate, ' TRUNC (sysdate+1) +1/24 ');

End

/

Start Job:

Begin

Dbms_job.run (44);

Commit

End

/

To see if the job exists:

Select Job, Next_date, next_sec, failures, broken from user_jobs;

Oracle timed query data is inserted into a new table (job+ stored procedure)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.