OracleSchedulerJob学习笔记
10g_调度任务
program 定义job每次运行的程序,说白了是job每次都干什么.
创建job的时候可以指定job的schedule和program,或者只指定2者之一,或是都不指定.如果都不指定,就相当于9i的job了,自定义运行时间和运行任务.下面是一些例子:
10G scheduler
EOF
[oracle@vm4 ~]$
1 创建一个program,调用第0步创建的shell脚本:C:>sqlplus system/oracle@vm4
SQL*Plus: Release 9.2.0.1.0 - Production on 星期一 10月 17 18:39:01 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning and Data Mining options
7 comments => 'test shell script'
8 );
9 end;
10 /
PL/SQL 过程已成功完成。
2 创建一个schedule,每1小时执行1次:
SQL> begin
2 dbms_scheduler.create_schedule
3 (
4 schedule_name => 'SCHEDULE_1_HOUR',
关于Oracle的job的一些总结
6、一些必要的参数
修改initsid.ora参数
job_queue_processes = 4
job_queue_interval = 10
job_queue_keep_connections=true
修改可执行作业个数为20个
ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 20
修改取消限制模式
ALTER SYSTEM DISABLE RESTRICTED SESSION;
7、两个必要的表
user_jobs及dba_jobs_running
8、相关的几个JOB操作
删除job:dbms_job.remove(jobno);
修改要执行的操作:job:dbms_job.what(jobno,what);
时间
-------------------
2001/01/07 23:51:21
2001/01/07 23:52:22
2001/01/07 23:53:24
5、删除JOB
SQL> begin
2 dbms_job.remove(:job1);
3 end;
4 /
insert into agri_exhibition_basecur (messid,title,type,pub_date) select id,title,sort,pub_date from agri_message where (trunc(sysdate-pub_date)=0 and rownum<6) and sort='求' ;
修改下次执行时间:dbms_job.next_date(job,next_date);
oracle 作业计划
oracle 作业计划
Oracle作业计划是指在Oracle数据库中安排和管理定期执行
的任务或作业。
这些作业可以是数据库维护任务、数据备份任务、
报表生成任务等。
以下是关于Oracle作业计划的一些方面的详细解释:
1. 作业类型,Oracle作业可以分为多种类型,包括备份和恢复、性能优化、数据清理、统计信息收集等。
每种类型的作业都有
不同的特点和执行频率。
2. 作业调度,Oracle作业计划可以通过Oracle Scheduler来
进行调度和管理。
Oracle Scheduler提供了灵活的调度功能,可以
根据作业的执行时间、频率、依赖关系等进行配置。
3. 作业参数,在创建作业计划时,可以指定一些参数,如作业
的执行时间、执行频率、作业的优先级、作业的依赖关系等。
这些
参数可以根据实际需求进行配置,以确保作业能够按时、按需执行。
4. 监控和日志,Oracle作业计划提供了监控和日志功能,可
以实时查看作业的执行情况和日志信息,以便及时发现和解决问题。
5. 安全性,在配置作业计划时,需要考虑安全性因素,确保作业的执行不会对数据库的安全性造成影响。
可以通过合理的权限管理和作业执行策略来保证作业的安全性。
总之,Oracle作业计划是数据库管理中非常重要的一部分,合理的作业计划可以有效地提高数据库的运行效率和数据的安全性。
通过灵活的调度、合理的参数配置和及时的监控,可以确保作业按时、按需地执行,从而保证数据库的稳定和安全运行。
OracleJob学习--两种不同Job使用区别
OracleJob学习--两种不同Job使⽤区别1.两种不同的JobOracle中有两种建⽴Job的⽅式:1)建⽴user_job定时任务declarejob number;BEGINDBMS_JOB.SUBMIT(JOB => job, /*⾃动⽣成JOB_ID*/WHAT => 'proc_add_test;', /*需要执⾏的存储过程名称或SQL语句*/NEXT_DATE => sysdate+3/(24*60), /*初次执⾏时间-下⼀个3分钟*/INTERVAL => 'trunc(sysdate,''mi'')+1/(24*60)' /*每隔1分钟执⾏⼀次*/);commit;end;执⾏之后可以通过:select * from user_jobs;2)通过调度器建⽴定时任务 begin sys.dbms_scheduler.create_job(job_name => 'job_name', job_type => 'PLSQL_BLOCK', job_action => 'declare PRM_ERRCODE number; PRM_ERRMSG varchar2(200); begin proc_add_test(PRM_ERRCODE,PRM_ERRMSG); end;', start_date => to_date('01-04-2021 00:00:00', 'dd-mm-yyyy hh24:mi:ss'), repeat_interval => 'Freq=Monthly;Interval=1', end_date => to_date(null), job_class => 'DEFAULT_JOB_CLASS', enabled => true, auto_drop => true, comments => '测试job'); end;2.两种Job定时任务的不同之处1)两种Job都可以调⽤已有的存储过程进⾏定时执⾏。
OracleJob的使用(定时执行)
OracleJob的使⽤(定时执⾏)oracle中的job能为你做的就是在你规定的时间格式⾥执⾏存储过程,定时执⾏⼀个任务。
下⾯是⼀个⼩案例,定时每15分钟向⼀张表插⼊⼀条数据⼀1.创建⼀张测试表-- Create tablecreate table A8(a1 VARCHAR2(500))tablespace DSP_DATApctfree 10initrans 1maxtrans 255storage(initial 64Knext 1Mminextents 1maxextents unlimited);2.创建存储过程实现向测试表插⼊数据create or replace procedure proc_add_test asbegininsert into a8 values (to_char(sysdate, 'yyyy-mm-dd hh:mi'));/*向测试表插⼊数据*/commit;end;3.创建job定时任务实现⾃动调⽤存储过程(当前时间 17:03)declarejob number;BEGINDBMS_JOB.SUBMIT(JOB => job, /*⾃动⽣成JOB_ID*/WHAT =>'proc_add_test;', /*需要执⾏的存储过程名称或SQL语句*/NEXT_DATE => sysdate+3/(24*60), /*初次执⾏时间-下⼀个3分钟*/INTERVAL =>'trunc(sysdate,''mi'')+1/(24*60)'/*每隔1分钟执⾏⼀次*/);commit;end;4.也就是应该从17:06开始每隔1分钟执⾏⼀次存储过程下⾯是截⽌17:12分的测试表的数据⼆1.可以通过查询系统表查看该job信息select*from user_jobs;2.⼿动sql调⽤job (直接调⽤job可以忽略开始时间)beginDBMS_JOB.RUN(40); /*40 job的id*/end;3.删除任务begin/*删除⾃动执⾏的job*/dbms_job.remove(40);end;4.停⽌jobdbms.broken(job,broken,nextdate);dbms_job.broken(v_job,true,next_date); /*停⽌⼀个job,⾥⾯参数true也可是false,next_date(某⼀时刻停⽌)也可是sysdate(⽴刻停⽌)。
【Oracle学习笔记】定时任务(dbms_job)
【Oracle学习笔记】定时任务(dbms_job)⼀、概述Oralce中的任务有2种:Job和Dbms_job,两者的区别有:1. jobs是oracle数据库的对象, dbms_jobs只是jobs对象的⼀个实例,就像对于tables, emp和dept都是表的实例。
2.创建⽅式也有差异,Job是通过调⽤dbms_scheduler.create_job包创建的,Dbms_job则是通过调⽤dbms_job.submit包创建的。
3.两种任务的查询视图都分为dba和普通⽤户的,Job对应的查询视图是dba_scheduler_jobs和user_scheduler_jobs,dbms_jobs对应的查询视图为dba_jobs和user_jobs。
这⾥主要是介绍Dbms_job。
⼆、使⽤1、创建job:1BEGIN2 DBMS_JOB.SUBMIT(3 JOB OUT BINARY_INTERGER,--输出变量,是此任务在任务队列中的编号,也可以⾃定义,⼀般不传4 WHAT IN VARCHAR2,--执⾏的任务的名称及其输⼊参数5 NEXT_DATE IN DATE DEFAULT SYSDATE,--任务执⾏的时间6 INTERVAL IN VARCHAR2DEFAULT NULL,--任务执⾏的时间间隔7 NO_PARSE IN BOOLEAN DEFAULT FALSE,--⽤于指定是否需要解析与作业相关的过程8 INSTANCE IN BINARY_INTEGER DEFAULT ANY_INSTANCE,--⽤于指定哪个例程可以运⾏作业9 FORCE IN BOOLEAN DEFAULT FALSE--⽤于指定是否强制运⾏与作业相关的例程10 );11END新⼿可以使⽤窗⼝创建:2、删除job: dbms_job.remove(jobno); -- jobno任务号3、修改要执⾏的操作: job:dbms_job.what(jobno, what); --指定任务号以及存储过程4、修改下次执⾏时间:dbms_job.next_date(jobno, next_date); --指定任务号的时间5、修改间隔时间:dbms_job.interval(jobno, interval); --指定任务号的间隔时间6、改变与作业相关的所有信息,包括作业操作,作业运⾏⽇期以及运⾏时间间隔等.1 dbms_job.change(2 job in binary_integer,3 what in varchar2,4 next_date in date,5 interval in varchar2,6 instance in binary_integer default null,7 force in boolean default false8 );例⼦:dbms_job.change(2,null,null,'sysdate+2');6、启动job: dbms_job.run(jobno); --指定任务号启动7、停⽌job: dbms.broken(jobno, broken, nextdate); –broken为boolean值 N代表启动,Y代表没启动(STOP)三、Interval 说明间隔/interval是指上⼀次执⾏结束到下⼀次开始执⾏的时间间隔,当interval设置为null时,该job执⾏结束后,就被从队列中删除。
oracle 计划任务
Oracle计划任务博客分类:OracleOracle在10g版本以前,计划任务用的是DBMS_JOB包,10g版本引入DBMS_SCHEDULER来替代先前的DBMS_JOB,在功能方面,它比DBMS_JOB提供了更强大的功能和更灵活的机制管理。
一、 DBMS_JOB1、查看数据库中定时任务的最多并发数,一般设置为102、设置数据库中定时任务的最多并发数,如果设置为0,那么数据库定时作业是不会执行的。
Sql代码3、Job的使用说明:4、创建Job事例1:Job执行间隔时间的Interval参数说明Sql代码5、创建Job事例2:其中最后一个参数'sysdate+1/1440'表示时间间隔为每分钟。
其它常用的时间间隔的设置如下:(1)如果想每天凌晨1点执行,则此参数可设置为'trunc(sysdate)+25/24';(2)如果想每周一凌晨1点执行,则此参数可设置为'trunc(next_day(sysdate,1))+25/24';(3)如果想每月1号凌晨1点执行,则此参数可设置为'trunc(last_day(sysdate))+25/24';(4)如果想每季度执行一次,则此参数可设置为'trunc(add_months(sysdate,3),'Q')+1/24';(5)如果想每半年执行一次,则此参数可设置为'add_months(trunc(sysdate,'yyyy'),6)+1/24';(6)如果想每年执行一次,则此参数可设置为'add_months(trunc(sysdate,'yyyy'),12)+1/24'。
6、Job调度任务查看操作7、Job其它操作(1)启动运行JobSql代码(2)删除job: dbms_job.remove(jobno);(3)修改要执行的操作job: dbms_job.what(jobno,what);(4)修改下次执行时间:dbms_job.next_date(job,next_date);(5)修改间隔时间: dbms_job.interval(job,interval);(6)停止job: dbms.broken(job,broken,nextdate);二、DBMS_SCHEDULER1、 DBMS_SCHEDULER的功能更强大,定义更灵活,增强了与系统的交互性。
Job Scheduler Oracle FLEXCUBE 大纲与说明说明书
Job Scheduler Oracle FLEXCUBE Universal BankingRelease 11.3.83.02.0[April] [2014] Oracle Part Number E53607-01Job SchedulerTable of Contents1.ABOUT THIS MANUAL................................................................................................................................1-1 1.1I NTRODUCTION...........................................................................................................................................1-11.1.1Audience............................................................................................................................................1-11.1.2Acronyms and Abbreviations.............................................................................................................1-11.1.3Glossary of Icons...............................................................................................................................1-12.JOB SCHEDULING........................................................................................................................................2-1 2.1I NTRODUCTION...........................................................................................................................................2-1 2.2D EFINING J OBS...........................................................................................................................................2-1 2.3S CHEDULING J OBS......................................................................................................................................2-4 2.4C ONTROLLING J OBS...................................................................................................................................2-5 2.5N OTIFICATION P ROCESS.............................................................................................................................2-6 2.6V IEWING N OTIFICATION P ARAMETERS.....................................................................................................2-10 2.7EMS P ROCESS WITH SCHEDULING ARCHITECTURE...................................................................................2-112.7.2Approach.........................................................................................................................................2-113.SCREEN GLOSSARY....................................................................................................................................3-1 3.1F UNCTION ID L IST......................................................................................................................................3-11. About this Manual 1.1 IntroductionThis manual is designed to help acquaint you with the Job scheduling process in OracleFLEXCUBE.1.1.1 AudienceThis manual is intended for the following User/User Roles:Role FunctionBack office data entry Clerks Input functions for maintenance related to the interface.Back office Managers/Officers Authorization functions.1.1.2 Acronyms and AbbreviationsAbbreviation DescriptionSystem Unless and otherwise specified, it shall always refer to Oracle FLEXCUBEsystem1.1.3 Glossary of IconsThis User Manual may refer to all or some of the following icons.Icons FunctionNewCopySaveDeleteUnlockPrintCloseRe-openReverseTemplateIcons FunctionRoll-overHoldAuthorizeLiquidateExitSign-offHelpAdd rowDeleterowOptionListConfirmEnterQueryExecuteQueryRefer the Procedures User Manual for further details about the icons.2. Job Scheduling 2.1 IntroductionJob scheduling is the process where different tasks get executed at pre-determined time or when the right event happens. A job scheduler is a system that can be integrated with other softwaresystems for the purpose of executing or notifying other software components when a pre-determined, scheduled time arrives. The two types of job schedulers used in Oracle FLEXCUBE FCJ architecture are as follows:∙Quartz - provides scheduler interface to enable operations such as scheduling and un-scheduling of jobs and starting, stopping, pausing the scheduler∙Flux - software component used for performing enterprise job scheduling2.2 Defining JobsA job is a business activity which the system performs repeatedly on timely basis. OracleFLEXCUBE enables you to define a job and schedule it using ‘Job Maintenance’ screen. You can invoke this screen by typing ‘STDJOBMT’ in the field at the top right corner of the Application tool bar and clicking on the adjoining arrow button.You can specify the following fields in this screen.Job CodeSpecify the unique code to identify the Job.Job DescriptionSpecify a brief description of what the job is supposed to do.Job GroupSpecify the job group name to represent the same group of jobs for identification.Job TypeSelect the type of job from the drop-down list. The following options are available for selection: ∙PL/SQL∙JAVAMax Number InstancesSpecify the maximum number of instances that needs to be queued up.ExampleIf a job runs for more than the duration defined, the next instance of the same job will be ready for processing. This parameter defines the job’s behavior in such cases,If you maintain the job as ‘STATEFUL’, then the number of such missed instances will be queued up so that it would start executing once this long running job ends. This field specifies the number of such job instances that needs to be queued up.If you maintain the job as ‘STATELESS’, it indicates the number of threads that can be executed in parallel. If you maintain the max number instances as ‘0’,no instances are queued or parallel processed till the current running instance is completed.SchedulerSpecify the name of the scheduler. The system defaults the name to ‘SchedulerFactory’. However, you can modify this name. This signifies the scheduler name which is configured as part of infra.Trigger TypeSelect the type of the trigger from the drop-down list. The following options are available: ∙Simple - Interval based jobs.(i.e., every one hour)∙Cron - Time based jobs.(i.e., Friday 4:30PM)Scheduler TypeSelect the type of scheduler from the drop-down list. The following options are available: ∙Quartz∙FluxPrioritySelect the priority on which the system should execute the jobs in the scheduler from the drop-down list. The following options are available.∙Normal∙HighIf two jobs with different priorities fire at the same time, then system gives preference to the job with higher priority.Message QueueSpecify the default JMS queue to which a job needs to send message. You can specify this only if the job has to send messages to JMS.Cron ExpressionSpecify the corresponding Cron expression for a job with trigger type as ‘Cron’. You need to do this to determine the time and interval of job firing.Class or ProcedureSpecify the Java class file name if job type is ‘Java’ or the PL/SQL procedure name if the job type is ‘PL/SQL’. This denotes which java class or pl/sql procedure the system should call when a job fires.Number of SubmissionsSpecify the number of times a job can fire before it is unscheduled from scheduler. This applies only to trigger types maintained as ‘Simple’.IntervalSpecify the time interval between jobs. This applies only to trigger types maintained as ‘Simple’. Trigger ListenerSpecify a java class as a trigger listener which will be notified of events such as before job fired, after job completed, misfired jobs.ActiveCheck this box to set the job as active. The scheduler does not pick the inactive jobs for scheduling.Ds NameSpecify the name of the database schema to which the job has to connect. This attribute is used in case of multi instance deployment of Oracle FLEXCUBE application.Logging RequiredCheck this box to indicate that system should log each firing of job. This helps in logging the firing time of job and key log info as part of that firing. This also enables tracking of each job’s firing times and helps in identifying miss-fired jobs.Startup ModeSpecify start up mode of the job from the drop-down list. The following options are available: ∙Auto - The job starts automatically when Oracle FLEXCUBE application starts∙Manual - You should start the job manually in job controller by resuming the job.Parameter DetailsYou can specify the job specific parameters, which are passed to job class or procedure atruntime. The following details are captured here:Parameter NameSpecify the name of the job parameter. The parameter name you specify here is passed to job class or procedure at run time.Data TypeSpecify the data type of the parameter.Parameter ValueSpecify the value of the parameter.2.3 Scheduling JobsAll jobs for scheduling are stored in a static data store and each job is associated with a name indicating where the job has to execute. Jobs are created in the Application Server and arescheduled based on this data.The job name should be unique across the schedulers available in the system.When the application server starts, the job details from static data store will get cached. These cached jobs will then be scheduled using either the quartz or flux scheduler.For example, the notification process can be handled by the job schedulers as follows:1. When a contract is created in Oracle FLEXCUBE, a database level trigger acting on thecontract main table inserts details like base table name, primary key fields, primary keyvalues and branch code into a notification log table and sets the process status of theinserted record as ‘U’ (unprocessed).2. The scheduled job polls the notification log table for unprocessed records and validateswhether notification is required.3. If notification is not required, then the process status is set to ‘N’ (not required) in notificationlog table.4. If notification is required then notifications are sent to the respective destination and theprocess status of the record is changed to ‘P’ (Processed) in notification log table.2.4 Controlling JobsThe details of jobs that are scheduled can be viewed using the ‘Job Details’ screen. In this screen you can pause or resume a job that has been scheduled. You can invoke the ‘Job Details’ screen by typing ‘SMSJOBBR’ in the field at the top right corner of the Application tool bar and clickingthe adjoining arrow button.You can a search for a scheduled job by specifying any of the following:Job NameSelect the name of the job that you want to search for from the option list provided.StateSelect the state of the job you want to search for from the option list provided. The followingoptions are possible for Quartz schedulers:∙Acquired∙Waiting∙Blocked∙PausedFor Flux schedulers, the options are as follows:∙Firing∙Waiting∙PausedSchedulerSelect the scheduler to which the job you want to search for has been assigned.Job GroupSelect the group to which the job you want to search for belongs, from the option list provided.Next Fire TimeSelect the time when the job is scheduled to be run next.Click ‘Search’ button to view the details related to the job. You can pause a job by selecting it and clicking the ‘Pause’ button.You can resume a paused job by clicking ‘Resume’ button and the job is scheduled for its nextfire time.A job can take any of the following states.∙COMPLETE - This indicates that the trigger does not have remaining fire-times in its schedule.∙NORMAL - This indicates that the trigger is in the "normal" state.∙BLOCKED - A job trigger arrives at the blocked state when the job that it isassociated with is a ‘Stateful’ job and it is currently executing.∙PAUSED - This indicates that the job is manually paused from executing.∙ERROR - A job trigger arrives at the error state when the scheduler attempts to fire it, but cannot due to an error creating and executing its related job. Also, a job arrives atERROR state when the associated class for the job is not present in class path. 2.5 Notification ProcessThe notification process is in two layers. In the first layer the notification process as part of jobs in FCJ scheduler sends minimal data required for notification to an internal JMS queue. In thesecond layer the notification process as part of an MDB that listens on internal JMS queue builds final notifications and sends them to their intended destinations.The Notification Process in Oracle FLEXCUBE using the jobs scheduler is as follows:1. The trigger on the base table inserts key details into a static notification log table instead ofOracle AQ.2. Once Job is triggered, a request is sent to EJB layer from job execution class and thenotification log table is polled for unprocessed records.3. Each unprocessed record is locked.4. The record is verified against the notification maintenance and checked whether notificationis to be sent or not.5. If notification is to be sent, pre notification message xml is built and it is sent to internalnotify_queue(JMS queue).6. The job is then rescheduled to fire next time based on the previous execution.The notification process in MDB is as follows:7. The Notification MDB listens on the internal notify JMS queue.8. On any message received, the MDB identifies which schema to connect using the JNDIname being present as part of the message xml.9. Gateway notification processing package is called from MDB in order to build the actualnotifications.10. In MDB the notifications built is processed and sent to the destination specified incorresponding notification.11. In case of any exception the whole transaction is rolled back.12. If all notifications are successfully processed then transaction is committed.The flow chart of notification process in scheduler:The flow chart for notification process in MDB:2.6 Viewing Notification ParametersYou can view and amend certain notification parameters in Oracle FLEXCUBE using ‘Gateway Notification Maintenance’ screen. You can invoke this screen by typing ‘IFDNOTIF’ in the field at the top right corner of the Application tool bar and clicking on the adjoining arrow button.Notification CodeThe system displays a unique code to identify a notification.DescriptionThe system displays a brief description of the notification. However, you can modify thedescription in this screen.OperationSelect the type of operation for the notification from the following.∙Insert - to indicate a new operation of notification function∙Update - To indicate a modification operation of notificationGateway OperationSpecify the gateway operation name to execute query for the mentioned service.Gateway ServiceSpecify the gateway service to be used to get the full screen response.IO Request NodeSpecify the gateway IO request node to be used in querying operation.Specific NotificationCheck this box to indicate the system to send specific notification. The system handles anydeviation from generic notification process by creating specific triggers once you check this field.Full Screen Reply RequiredCheck this box to indicate that the full screen notification response has to be sent. Otherwise, the primary key response notification is sent.Head OfficeCheck this box to send notification only from head office.2.7 EMS Process with scheduling architecture2.7.1.1 The new EMS Process:Incoming EMS ProcessA job is scheduled to poll the incoming folder on timely basis. Once a message is received in thefolder, the job picks the message and sends it to an internal JMS queue. An MDB listening on the queue will read the message and identifies the media and processes the message.Outgoing EMS ProcessA job is scheduled to poll the outgoing messages that are generated but not handed off. Eachmessages polled will be sent to an internal JMS queue.A MDB, acting upon the internal JMS queue will pick the message from queue and sends themessage to appropriate destination (Folder, or e-mail, or JMS queue).2.7.2 ApproachThe Outgoing EMS Process happens in two layers.1. The EMS process as part of jobs in FCJ scheduler, polls the outgoing message table ofFLEXCUBE for generated and un-send messages. The job then sends minimal data about themessage to be handed off, to an internal JMS queue.2. The EMS process as part of an MDB that listens on internal JMS queue to build final messageand to send to their intended destinations.The Incoming EMS Process happens in two layers.1. The EMS process as part of jobs in FCJ scheduler, which polls the pre configured folder formessages and sends the messages read, to EMS internal queue.2. The EMS process as part of an MDB, that listens on internal JMS queue identifies the messagefrom queue and calls the incoming messages service package in backend to process themessage. Additionally, the MDB can be made an independent unit to listen on external JMS toprocess incoming messages.The Incoming EMS Process as part of jobs scheduler is as follows:1. Once job is triggered, it polls for messages in a folder(Configured for incoming messages).2. Each message is then sent to an internal JMS queue.3. The job is then rescheduled to fire next time.EMS processes in MDB are as follows:1. An MDB that listens on the internal EMS incoming queue will receive the message.2. The media details are identified and incoming message processing package in backend is calledto process the message.3. In case of any exception while processing, message will be sent to a deferred queue.In case of messages directly arrive to JMS queue instead of a folder; the same MDB will beconfigured to listen on specific queue.3. Screen Glossary 3.1 Function ID ListThe following table lists the function id and the function description of the screens covered as part of this User Manual.Function ID Function DescriptionIFDNOTIF Gateway Notification MaintenanceSMSJOBBR Job DetailsSTDJOBMT Job MaintenanceJob Scheduler[April] [2014]Version 11.3.83.02.0Oracle Financial Services Software LimitedOracle ParkOff Western Express HighwayGoregaon (East)Mumbai, Maharashtra 400 063IndiaWorldwide Inquiries:Phone: +91 22 6718 3000Fax:+91 22 6718 3001/financialservices/Copyright © 2005, 2014, Oracle and/or its affiliates. All rights reserved.Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are ‘commercial computer software’ pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government.This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate failsafe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.This software or hardware and documentation may provide access to or information on content, products and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.。
Oracle数据库学习笔记
Oracle数据库学习笔记Oracle数据库基础 orcale属于关系型数据库,适⽤于各类⼤,中,⼩,微机环境,是⼀种⾼效率、可靠性好的、适应⾼吞吐量的数据库⽅案。
学习,实验完全免费,商⽤需要⽀付相应费⽤。
Oracle 数据库包括数据库实例,和数据库,⼆者脱离谁都没有存在的价值。
实例是⽤来操作数据库的对象,数据库是⽤来存储数据使⽤的。
Oracle主要组件包含实例组件,数据库组件。
SGA(System Global Area)是Oracle Instance的基本组成部分,PGA(Process Global Area)是为每个连接到Oracle database的⽤户进程保留的内存。
每个实例只有⼀个SGA,所有的进程都能访SGA。
PGA是程序全局区,每个⼀个进程都⼀个PGA,PGA是私有的,只有对应进程才能访问对应的PGA。
数据库中包含:参数⽂件,⼝令⽂件,数据库⽂件,控制⽂件,⽇志⽂件以及归档⽇志⽂件。
Oracle实例进场包含⽤户进程,服务器进程和后台进程。
SGA:系统全局区 系统全局区包含共享池,数据缓冲区,⽇志缓冲区。
“共享池”:是对SQL,PL/SQL程序进⾏语法分析,编译,执⾏的内存区;由库缓存和数据字典缓存组成;其⼤⼩直接影响数据库性能。
“数据缓冲区”:临时存储从数据库读⼊的数据,所有⽤户共享,数据缓存区的⽬的是加快数据读写。
“⽇志缓冲区”:⽇志记录数据库所有修改信息,其先产⽣于⽇志缓冲区,当达到⼀定数量时,由后台进程将⽇志数据写到⽇志⽂件中。
PGA:程序全局区 PGA包含单个服务器进程所需要的数据和控制信息,在⽤户进程连接到数据库并创建⼀个会话时⾃动分配的,保存每个与数据库连接的⽤户进程所需要的信息。
PGA为⾮共享区,只能单个进程使⽤,当⼀个⽤户会话结束,PGA释放。
后台进程 后台进程中包含PMON(进程监视器(Process Monitor)),SMON(系统监视器(System Monitor)),DBWR(数据库书写器(Database Write)),LGWR(⽇志书写器(Log Write)),CKPT(检查点(Checkpoint)),以及其他。
dba_scheduler_job_run_details各个项目的意义
`DBA_SCHEDULER_JOB_RUN_DETAILS`是Oracle数据库中的一个视图,它提供了定时任务或调度任务最后一次执行的详细信息。
以下是该视图中各个项目(字段)的含义:
1. `JOB_NAME`:定时任务名称,这是数据库对象的名称,如一个存储过程或函数。
2. `RUN_ID`:运行ID,这是每次作业运行的唯一标识符。
3. `INSTANCE_NAME`:运行实例名称,这是执行作业的数据库实例的名称。
4. `START_TIME`:开始运行时间,这是作业开始运行的时间。
5. `RUN_DURATION`:持续时间,这是作业运行的总时间长度。
6. `NUM_ATTEMPTS`:重试次数,这是作业在失败后自动重试的次数。
7. `STATUS`:状态,这是作业的当前状态,如"成功"、"失败"或"正在运行"。
8. `ERROR_CODE`:错误代码,这是作业运行失败时的错误代码。
9. `ORACLE_ERROR_CODE`:调度任务结果,这是Oracle数据库返回的错误代码。
10. `RESULT`:运行结果,这是作业的最终结果,如"成功"、"失败"或"警告"。
使用此视图可以帮助数据库管理员确定定时任务或调度任务的运行情况,是否出现了任何故障,以及计算调度任务的性能,比如它运行的时间和是否需要重新执行等。
ORACLE 知识整理(JOB)
你先找到JOB号:SELECT JOB FROM USER_JOBS WHERE WHAT='ES_DBA.P_DELETE_JBPM_DATA' 如:为62则再运行以下语句:Begindbms_job.remove(job => 62);End;/Commit;oracle job管理SVRMGR> select * from dba_jobs;初始化相关参数job_queue_processesalter system set job_queue_processes=39 scope=spfile;//最大值不能超过1000 ;job_queue_interval = 10 //调度作业刷新频率秒为单位DBA_JOBS describes all jobs in the database.USER_JOBS describes all jobs owned by the current user1 select job,what,to_char(last_date,'yyyy-mm-dd HH24:mi:ss'),to_char(next_date,'yy yy-mm-dd HH24:m),interval from dba_jobs where job in (325,295)2 select job,what,last_date,next_date,interval from dba_jobs where job in (1,3);查询job的情况。
show paramter background_dump_dest.看alter.log 和traceSVRMGR> select * from dba_jobs;初始化相关参数job_queue_processesalter system set job_queue_processes=39 scope=spfile;//最大值不能超过1000job_queue_interval = 10 //调度作业刷新频率秒为单位DBA_JOBS describes all jobs in the database.USER_JOBS describes all jobs owned by the current user1 select job,what,to_char(last_date,'yyyy-mm-dd HH24:mi:ss'),to_char(next_date,'yy yy-mm-dd HH24:m),interval from dba_jobs where job in (325,295)2 select job,what,last_date,next_date,interval from dba_jobs where job in (1,3);查询job的情况。
oracle19c scheduler job error log alert log
oracle19c scheduler job error log alert log摘要:1.Oracle19c 简介2.Scheduler Job 错误日志和警报日志的作用3.解决Oracle19c Scheduler Job 错误日志和警报日志的方法4.总结正文:一、Oracle19c 简介Oracle19c 是Oracle 公司的最新版本,提供了更强大的数据库管理和优化功能。
在使用Oracle19c 时,可以通过Scheduler Job 来定期执行一些数据库维护任务,如备份、导入/导出数据等。
二、Scheduler Job 错误日志和警报日志的作用在Oracle19c 中,Scheduler Job 错误日志和警报日志用于记录任务执行过程中的错误信息和异常事件。
这些日志可以帮助数据库管理员发现问题并及时进行处理。
1.错误日志(Alert Log):记录了Scheduler Job 执行过程中产生的错误信息,如无法连接到数据库、文件读写错误等。
2.警报日志(Error Log):记录了Scheduler Job 执行过程中遇到的警告和异常事件,如任务超时、磁盘空间不足等。
三、解决Oracle19c Scheduler Job 错误日志和警报日志的方法1.查看错误日志和警报日志:使用sqlplus 命令登录到Oracle19c 数据库,然后执行以下语句查看日志:```SELECT * FROM dba_alerts;SELECT * FROM dba_errors;```2.根据日志信息分析问题:根据日志中的错误信息和异常事件,分析可能导致问题的原因。
例如,如果日志中显示无法连接到数据库,可能是数据库服务未启动或数据库连接参数设置不正确。
3.解决问题:针对分析出的问题,采取相应的解决措施。
如启动数据库服务、修改数据库连接参数等。
4.清理日志:问题解决后,可以使用以下命令清理错误日志和警报日志:```BACKUP LOG dba_alerts TO"/u01/app/oracle/oradata/backup/dbalert.log";BACKUP LOG dba_errors TO"/u01/app/oracle/oradata/backup/dberror.log";```四、总结Oracle19c Scheduler Job 错误日志和警报日志对于数据库管理员来说非常重要,可以帮助他们发现和解决任务执行过程中的问题。
Oracle数据库的SCHEDULE(调度程序)
Oracle数据库的SCHEDULE(调度程序)很多情况下,数据库管理员或用户需要自动调度和运行很多类型的作业,例如,执行维护工作(如数据库备份);数据加载和验证例程;生成报表;收集优化程序统计信息或执行业务流程。
可以使用调度程序功能指定任务在将来某个时间点运行。
作业可以在数据库中、在驻留数据库实例的机器上甚至在远程机器上运行。
可以结合使用调度程序和Resource Manager(资源管理器)。
调度程序可以激活Resource Manager计划,并按照为各种Resource Manager使用者组指定的优先级来运行作业。
调度程序是在Oracle 10g版本中引入的,在11g版本中得到了大大增强。
较早的数据库版本通过DBMS_JOB功能提供作业调度功能。
为了达达到向后兼容的目的,当前版本依然支持此功能,但它的功能多样性远不及调度程度。
1、调度程序体系结构数据字典包含一个作为所有调度程序作业的存储点的表。
可以通过DBA_SCHEDULER_JOBS视图查询此表。
作业队列协调器后台进程CJQ0监视此表,根据需要启动作业队列进程Jnnn来运行作业。
如果在任何定义的、活动的调度程序作业,就自动启动CJBQ0进程。
根据需要启动Jnnn进程,但是最大数量受JOB_QUEUE_PROCESSES实例参数限制,该参数可以是0-1000(默认值)的任何值。
如果将值设为0,那么将不会运行调程。
作业队列协调器从作业队列表中选取作业,将它们传递给作业队列进程执行。
它还根据需要启动和终止作业队列进程。
要查看当前正在运行的进程,可查询V$PROCESS视图。
select program from v$process where program like '%J%';定义为过程的作业在数据库中运行。
作业也可以定义为操作系统命令或shell脚本:这些将作为外部操作系统任务运行。
作业的触发因素可以是时间或事件。
oracle查询优化改写技巧和案例(学习笔记)
o r a c l e查询优化改写技巧和案例(学习笔记)-标准化文件发布号:(9556-EUATWK-MWUB-WUNN-INNUL-DDQTY-KIIoracle查询优化改写技巧和案例(学习笔记)第一章将空值转换成实际值函数coalesce(exp1,exp2,...)返回第一个为非空的值,避免了返回空值;查找满足多个条件的行用到or:只要达到其中一个条件就可以的;查询所有的提成的员工:即提成不为空,comm is NOT NULL;这个很好的例子;用括号把多个条件给分隔开;在where字句中引用别名的列;即要引用别名的列时必须是一张表中的字段;select * from (sal as 工资 ,comm as 提成from emp) x where 工资 >2000;拼接列用“||”把各列连起来员工的工作是:ename || ‘的工作是’|| job在slect语句中使用条件逻辑即用case来解决:格式为字段,casewhen then ;when then ;else ;end as 别名情景:当工资<2000元时,就返回“过低”,<4000 就返回“过高”,复习考题:(P9)要按照工资档次统计人数;限制返回的行数用rownum是依次对数据做出的标识,是所有的数据取出来后才能确定其序号;rownum<= 2而不能rownum = 2;查询某个序号可以这样:select * from (select rownum as sn,emp.* from emp) where rownum<=2) where sn = 2;从表中随机返回n条记录先随机排序,再取数据(正确):select empno,ename from (select empno,ename from emp order by ()) where rownum <=3;先取数据再随机排序(错误):select empno,ename from emp where rownum <=3 order by ();模糊查询通配符主要有“like"、"_"、"%"如果查询中包含通配符就要用到转义字符:select * from v where vname like '\_like' ESCAPE '\';第二章给查询结果排序以指定的次序返回查询结果ASC:升序排序,从小到大排序;desc:倒序排序,即从大到小;order by 3 asc:表示按第三列排序:这种排序适用于该列取值不定时或者说经常改变的列,很方便,比如查询的列增加了,而我们只是排序第一列;按多个字段排序排序的字段要用","分开,比如:order by A desc, B asc;按字符串排序用到了substr()函数;主要是运用了快速查找顾客的电话的尾号4的顺序;substr(phone_number,-4) 表示后四位;()函数translate(expr,from_string,to_string):from_string和to_string以字符为单位,对应字符一一替换;如果to_string 为空,则返回空值;如果to_string对应的位置没有字符,删除from_string中列出的字符将会被消掉;运用:按数字和字母混合字符串中的字母排序把重要的东西提取出来,次要的东西踢掉,这道题是对translate的运用;先构造视图create or replace view v asselect empno || '' || ename as data from emp;select data,translate(data,'-09','-') as ename from v order by 2;处理排序空值在order by 的后面加个 NULLS FIRST或NULLS LAST;根据条件不同列中的值来排序领导对工资在1000到2000的感兴趣;select empno as 编码,ename as 姓名,sal as 工资 from emp where deptmo = 30 order by case when sal >= 1000 and sal <2000 then 1 else 2 end,3;第三章操作多个表(P要操作)2015/04/29 17:00all 与空字符串空字符串不等于空值;与or一般不用union all,这样避免的重复的数据;(P25要复习)为了消除bitmap convert的影响:alter session set"_b_tree_bitmap_plans" = false;但有是用union或or会被忽略,从而出现错误;不过加入一个唯一标识后,即保证了正确去重,又防止了不该发生的去重。
Oracle优化笔记
Oracle优化笔记业务是否⽤最优的⽅式来运⾏。
如果不是最优的⽅式那就对SQL进⾏优化。
查看数据库的执⾏计划技术⽅向上,应多考虑性能⽅⾯的问题积极参与到业务层⾯,从业务⾓度思考问题。
导致性能问题的可能原因1,表没有正确的创建索引---错误的执⾏计划2,表没有及时的分析---错误的执⾏计划3,热块---数据块的争⽤(反向索引?)4,锁的阻塞---业务设计缺陷、5,SQL解析消耗⼤量CPU---变量绑定6,低效的SQL---SQL⾃⾝的问题7,数据库整体负载过程---架构设计的问题性能问题的定位原则尽可能从⼩范围分析问题1,SQL层如果能从定位到SQL,就不要从会话层⾯分析已经定位到了某条SQL语句有问题,就针对该语句着⼿。
使⽤⼯具和执⾏计划来分析该语句,如使⽤:10053,10046(查看某条语句资源消耗情况)2,会话层如果能定位到会话,就不要从系统层⾯分析:V$SESSION, V$SESSTAT, V$SESSION_WAIT, V$SQL, V$LOCK SQL_TRACE3,系统层如果⽆法定位任何性能问题,从系统层⾯⼊⼿AWR(STATSPACK), OS tools(top, iostat)锁没有并发就没有锁Oracle中锁的分类:Enqueues--队列类型的锁,通常和业务相关的简写: enqLatches---系统资源⽅⾯的锁,⽐如内存结构,SQL解析锁的原则:1,只有被修改时,⾏才会被锁定,select操作不会在数据表中加锁。
2,当⼀条语句修改了⼀条记录,只有这条记录上被锁定,在Oracle数据库中不存在锁升级。
3,当某⾏被修改时,它将阻塞别⼈对它的修改。
4,当⼀个事务修改⼀⾏时,将在这个⾏上加上⾏锁(TX),⽤于阻⽌其它事务对相同⾏的修改。
5,读永远不会阻⽌写。
6,读不会阻塞写,但有唯⼀的⼀个例外,就是select ... for update.7,写永远不会阻塞读8,当⼀⾏被修改后,Oracle通过回滚段提供给数据的⼀致性读。
ORACLE全面学习Scheduler
三思笔记系列文章之全面学习ORACLE数据库SCHEDULER特性2009-08一、使用Jobs (2)1.1创建Jobs (2)1.2管理Jobs (4)二、使用Programs (6)2.1创建Programs (7)2.2管理Programs (8)三、使用Schedules (9)3.1创建和管理Schedules (10)3.2Schedules调度Programs执行的Jobs (11)3.3设置Repeat Interval (12)四、使用Events (16)4.1Scheduler抛出的Events (16)4.2Application抛出的Events (18)五、使用Chains (21)5.1创建Chains (22)5.2管理Chains (26)六、使用Job Classes (28)七、使用Windows (30)附:三思笔记系列文章快速链接: (33)所谓出于job而胜于job,说的就是Oracle10g后的新特性Scheduler啦。
在10g环境中,ORACLE建议使用Scheduler替换普通的job,来管理任务的执行。
其实,将Scheduler描述成管理job的工具已经太过片面了,10G 版本中新增的Scheduler绝不仅仅是创建任务这么简单。
提示:ORACLE中管理Scheduler是通过DBMS_SCHEDULER包,本章也以此为切入点,通过详细介绍DBMS_SCHEDULER包的使用,来演示如何使用Scheduler。
似乎本末倒置了,没关系,"三思笔记",俺的地盘俺做主。
一、使用Jobs所谓JOBS,其实就是Scheduler管理的一个(或多个)任务的执行调度。
1.1创建Jobs通过DBMS_SCHEDULER包来创建Jobs,是使用其CREATE_JOB过程。
在创建Job时,用户可以指定要执行的任务,调度信息(啥时候执行,执行周期,终止日期等)以及其它一些任务相关的属性。
oracle的job用法
oracle的job用法Oracle中的job用于计划和控制系统中的任务执行。
这个功能可以让用户自动化任务以及预定任务执行的时间。
在本篇文章中,我们将探讨Oracle的job用法。
1.创建job要创建一个job,首先需要创建一个job类,它必须实现job接口。
job接口有一个execute方法,该方法用于完成job执行时要执行的任务。
例如,以下类为一个实现job接口的示例:```javaimport org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;public class MyJob implements Job {public void execute(JobExecutionContext context) throws JobExecutionException {System.out.println("Hello Quartz!");}}```接下来,我们需要创建一个trigger,用于指定job的执行时间和频率。
在这里,我们将创建一个简单的trigger,该trigger将每5秒钟执行一次job。
```javaimport org.quartz.*;import org.quartz.impl.StdSchedulerFactory;public class QuartzTest {public static void main(String[] args) throws SchedulerException {JobDetail job = JobBuilder.newJob(MyJob.class).build(); Trigger trigger =TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeco nds(5).repeatForever()).b uild();Scheduler scheduler = newStdSchedulerFactory().getScheduler();scheduler.start();scheduler.scheduleJob(job, trigger);}}```在上面的示例中,我们首先创建了一个job,然后创建了一个trigger,其中定义了job的执行时间和频率。
【转】调度作业(OracleScheduler)
【转】调度作业(OracleScheduler)Oracle Scheduler可以帮助DBA或者数据库⽤户⾃动调度和运⾏各种类型的作业,⽐如数据库备份、收集优化器统计信息、⽣成各种报表或者执⾏业务流程等等,也可以把Schedule和Resource Manager结合起来通过时间窗⼝激活指定的Resource Plan,完成企业在资源管理和作业调度上的各种复杂需求,在10g之前可以通过DBMS_JOB⼯具来实现类似的功能,但毫⽆疑问,DBMS_SCHEDULER的灵活性和多样性⽐起⽼版本⼯具都有了极⼤的提升。
⼀. 功能概述Oracle Scheduler到底可以实现那些具体功能呢?来看⼀下官⽅⽂档给出的解释:Run database program units可以在本地或者远程数据库执⾏的数据库程序包括:PL/SQL 匿名块、PL/SQL 存储过程、JAVA 存储过程以及链Run external executables, (executables that are external to the database)执⾏外部的可执⾏⽂件,包括应⽤程序、Shell脚本、Windows批处理⽂件,如果要在远程主机执⾏外部作业,远程主机只需要安装Agent⽽不需要DatabaseSchedule job execution using the following methods:Time-based schedulingYou can schedule a job to run at a particular date and time, either once or on a repeating basis.Event-based schedulingYou can start jobs in response to system or business events. Your applications can detect events and then signal the Scheduler. Depending on the type of signal sent, the Scheduler starts a specific job.Dependency schedulingYou can set the Scheduler to run tasks based on the outcome of one or more previous tasks. You can define complex dependency chains that include branching and nested chains. Prioritize jobs based on business requirements.Controlling Resources by Job Class把有相同特性的Job指定到⼀个Job Class,再把Job Class映射到Resource Consumer Group,实现对调度作业的资源分配控制Controlling Job Prioritization based on Schedules通过时间窗⼝改变作业的优先等级,创建Window在⼀个时间范围激活相应的 Resource Plan 来控制不同作业在不同时段的优先等级Manage and monitor jobsExecute and manage jobs in a clustered environment⽀持在RAC环境管理调度作业⼆. 基本概念Oracle Scheduler包含的主要对象包括:Schedule,Program,Job,Job Class,Chain,Window,Database Destination,File Watcher,Credential ...具体介绍如下:Schedule (时间表)通过 DBMS_SCHEDULER 包中的过程 CREATE_SCHEDULE 定义调度的开始时间,结束时间以及重复间隔CREATE_EVENT_SCHEDULE 过程⽤来创建由事件触发的时间表,由⼀个特定时间段内的⼀个事件调起⼀项任务Program (程序)定义了作业的形式及内容,作业形式可以是PL/SQL 匿名块,也可以是存储过程或者外部可执⾏⽂件,执⾏的存储过程带有输⼊参数时必须以匿名块运⾏Job (作业)通过CREATE_JOB创建⼀个作业,这个存储过程使⽤了重载,所以输⼊参数的选择可以⾮常灵活,既可以独⽴设置作业的时间、内容、Job Class,也可以引⽤已经存在的Schedule 和 Program 来简化作业的创建Job Class (作业类)作业类中定义了Resource Consumer Group ,Service(RAC),⽇志等级,⽇志保留时间。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Oracle scheduler job 学习笔记
1.Scheduler增删改查操作
1.1.创建procedure
create or replace procedure aiki_test
as
begin
insert into aiki.a2 values(‘a’,88);
commit;
end;
1.2.创建scheduler job
begin
dbms_scheduler.create_job (
job_name => ‘aiki_test_name’,
job_class => ‘DEFAULT_JOB_CLASS’,
job_type => ‘STORED_PROCEDURE’,
job_action => ‘aiki_test’,
start_date => sysdate,
repeat_interval => ‘FREQ=DAILY; BYHOUR=10;BYMINUTE=18,19;’, end_date =>null,
comments => ‘系统临时测试’
);
end;
1.3.启用scheduler job
begin
dbms_scheduler.enable(‘aiki_test1’);
end;
1.4.删除scheduler job
begin
DBMS_SCHEDULER.DROP_JOB(JOB_NAME => ‘AIKI_TEST2’);
end;
1.5.查询scheduler job
select * from user_scheduler_jobs;
2.repeat_interval参数解释
2.1.描述
这个语法形式看起来复杂无比,其实实用起来很简单,之所以看起来复杂,是因为其功能太过灵活(之前的三思系列笔记中,已经阐述过灵活与复杂的关系),这里不准备逐条解释每一个语法细节,下面将着重通过一些常用设置,希望能够更有助于广大同仁的理解。
2.2.举例
1、设置任务仅在周5的时候运行:
REPEAT_INTERVAL => “FREQ=DAILY; BYDAY=FRI”;
REPEAT_INTERVAL => “FREQ=WEEKLY; BYDAY=FRI”;
REPEAT_INTERVAL => “FREQ=YEARLY; BYDAY=FRI”;
上述三条语句虽然指定的关键字小有差异,不过功能相同。
2、设置任务隔一周运行一次,并且仅在周5运行:
REPEAT_INTERVAL => “FREQ=WEEKLY; INTERVAL=2; BYDAY=FRI”;
3、设置任务在当月最后一天运行:
REPEAT_INTERVAL => “FREQ=MONTHLY; BYMONTHDAY=-1”;
4、设置任务在3月10日运行:
REPEAT_INTERVAL => “FREQ=YEARLY; BYMONTH=MAR; BYMONTHDAY=10”;
REPEAT_INTERVAL => “FREQ=YEARLY; BYDATE=0310”;
上述两条语句功能相同。
5、设置任务每10隔天运行:
REPEAT_INTERVAL => “FREQ=DAILY; INTERVAL=10”;
6、设置任务在每天的下午4、5、6点时运行:
REPEAT_INTERVAL => “FREQ=DAILY; BYHOUR=16,17,18”;
7、设置任务在每月29日运行:
REPEAT_INTERVAL => “FREQ=MONTHLY; BYMONTHDAY=29”;
8、设置任务在每年的最后一个周5运行:
REPEAT_INTERVAL => “FREQ=YEARLY; BYDAY=-1FRI”;
9、设置任务每隔50个小时运行:
REPEAT_INTERVAL => “FREQ=HOURLY; INTERVAL=50”;
2.3.简便方式
另外,你是否在怀念常规job中设置interval的简便,虽然功能较弱,但是设置操作非常简单,无须懊恼,其实SCHEDULER中的REPEAT_INTERVAL也完全可以按照那种方式设置,前面都说了,REPEAT_INTERVAL实际上是指定周期,直接指定一个时间值,当然也是周期喽。
比如说,设置任务每天执行一次,也可以设置REPEAT_INTERVAL参数值如下:REPEAT_INTERVAL => “trunc(sysdate)+1”
又比如设置任务每周执行一次:
REPEAT_INTERVAL => “trunc(sysdate)+7”
不过需要注意,这种方式仅用于创建SCHEDULER中jobs时使用,不能用于schedule。
日历表达式基本分为三部分: 第一部分是频率,也就是"FREQ"这个关键字,它是必须指定的; 第二部分是时间间隔,也就是"INTERVAL"这个关键字,取值范围是1-999. 它是可选的参数; 最后一部分是附加的参数,可用于精确地指定日期和时间,它也是可选的参数,例如下面这些值都是合法的:
BYMONTH,BYWEEKNO,BYYEARDAY,BYMONTHDAY,BYDAY,BYHOUR,BYMINUTE,BYSECOND。