我每天下午1:00都需要Oracle作业调度程序的帮助。我希望在该单个作业调度程序上执行两个查询。查询如
第一个是简单的删除查询。
delete from NEWS_NO_OF_VIEWS where TO_CHAR(MONTH_YEAR,'MM-YYYY') =
TO_CHAR(SYSDATE,'MM-YYYY')
,第二个是插入查询
INSERT INTO NEWS_NO_OF_VIEWS(NEWS_TYPE, NO_OF_VIEWS, MONTH_YEAR)
((SELECT 'Latest News' AS NEWS_TYPE,NVL(SUM(NO_OF_VIEWED),0) NO_OF_VIEWS,MONTH_YEAR FROM(
SELECT NO_OF_VIEWED,TO_CHAR(CREATED_DATE,'MM-YYYY') AS MONTH_YEAR FROM NEWS_LATEST_UR
UNION ALL
SELECT NO_OF_VIEWED,TO_CHAR(CREATED_DATE,'MM-YYYY') AS MONTH_YEAR FROM NEWS_LATEST_EN
) E WHERE MONTH_YEAR = TO_CHAR(SYSDATE,'MM-YYYY') GROUP BY MONTH_YEAR)
答案 0 :(得分:3)
你需要做的就是创建一个程序" give_some_proc_name"把你的" DELETE"和" INSERT"该过程中的语句并提交如下,以便将来如果你想添加或修改语句,你将很容易。
create or replace procedure give_some_proc_name
as
begin
delete from NEWS_NO_OF_VIEWS where TO_CHAR(MONTH_YEAR,'MM-YYYY') = TO_CHAR(SYSDATE,'MM-YYYY');
INSERT INTO NEWS_NO_OF_VIEWS(NEWS_TYPE, NO_OF_VIEWS, MONTH_YEAR)
((SELECT 'Latest News' AS NEWS_TYPE,NVL(SUM(NO_OF_VIEWED),0) NO_OF_VIEWS,MONTH_YEAR FROM(
SELECT NO_OF_VIEWED,TO_CHAR(CREATED_DATE,'MM-YYYY') AS MONTH_YEAR FROM NEWS_LATEST_UR
UNION ALL
SELECT NO_OF_VIEWED,TO_CHAR(CREATED_DATE,'MM-YYYY') AS MONTH_YEAR FROM NEWS_LATEST_EN
) E WHERE MONTH_YEAR = TO_CHAR(SYSDATE,'MM-YYYY') GROUP BY MONTH_YEAR);
commit;
end;
然后创建如下作业,从今天01:00 PM开始,每天下午01:00运行。在工作中,你的job_type将是" STORE_PROCEDURE"和工作行动将是" NAME_OF_PROCEDURE"即" give_some_proc_name"前缀模式名称为"。"分隔符如下。
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'give_some_name_to_job',
job_type => 'STORED_PROCEDURE',
job_action => 'schema_name.give_some_proc_name',
start_date => to_date(to_char(sysdate,'DD-MON-YYYY')||' 13:00:00','DD-MON-YYYY HH24:MI:SS'),
repeat_interval => 'freq=daily; byhour=13; byminute=0; bysecond=0;',
enabled => TRUE);
END;