|
Program1:
-
- BEGIN
- DBMS_SCHEDULER.CREATE_PROGRAM(
- program_name=>'"HR"."PROGRAM1"',
- program_action=>'begin
- insert into t05317_1 values ( sysdate );
- commit;
- end;',
- program_type=>'PLSQL_BLOCK',
- number_of_arguments=>0,
- comments=>'',
- enabled=>TRUE);
- END;
复制代码
Schedule1:
- BEGIN
- sys.dbms_scheduler.create_schedule(
- repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
- start_date => systimestamp at time zone 'Asia/Shanghai',
- end_date => to_timestamp_tz('2018-10-30 20:00:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
- schedule_name => '"HR"."SCHEDULE1"');
- END;
复制代码 Job1:
- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB1"',
- program_name => '"HR"."PROGRAM1"',
- schedule_name => '"HR"."SCHEDULE1"',
- job_class => '"DEFAULT_JOB_CLASS"',
- auto_drop => FALSE,
- enabled => TRUE);
- END;
复制代码
Program2:
- #!/bin/sh
- export LANG=en_US
- date >> /home/oracle/program2.txt
复制代码- BEGIN
- DBMS_SCHEDULER.CREATE_PROGRAM(
- program_name=>'"HR"."PROGRAM2"',
- program_action=>'/home/oracle/program2.sh',
- program_type=>'EXECUTABLE',
- number_of_arguments=>0,
- comments=>'',
- enabled=>TRUE);
- END;
复制代码 Schedule2:
- BEGIN
- sys.dbms_scheduler.create_schedule(
- repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
- start_date => systimestamp at time zone 'Asia/Shanghai',
- schedule_name => '"HR"."SCHEDULE2"');
- END;
复制代码 Job2:
- grant create external job to hr;
- select * from dba_scheduler_credentials;
- begin
- dbms_scheduler.create_credential(credential_name => 'credential1',
- username => 'oracle',
- password => 'oracle');
- end;
- grant execute on credential1 to hr;
复制代码-
- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB2"',
- program_name => '"HR"."PROGRAM2"',
- schedule_name => '"HR"."SCHEDULE2"',
- job_class => '"DEFAULT_JOB_CLASS"',
- auto_drop => FALSE,
- enabled => FALSE);
- DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB2"', attribute => 'credential_name', value => '"SYS"."CREDENTIAL1"' );
- sys.dbms_scheduler.enable( '"HR"."JOB2"' );
- END;
复制代码 在windows上外部作业(包含远程外部作业)容易报以下错误:
Host Credentials报错"Connection to host as user oracle failed: ERROR: Wrong password for user"的解决一例
我成功安装了Oracle 10g,可以登录到企业管理器,但无法执行一些操作,如数据库的备份调度,
执行恢复等,由于操作系统登录全权证书的问题。我被要求提供操作系统登录凭证才可以执行这些操作。
我在Host Credentials那里输入的是用户administrator,并且administrator已经加入到了ORA_DBA组
但执行操作是报错如下:
Error: Connection to host as user oracle failed:
ERROR: Wrong password for user
如何解决这个问题呢?
我查阅了Oracle的官方文档,发现如下解决办法:
1. 打开组策略,用gpedit.msc命令。
2. 逐步找到compute configuration -- windows setting -- security setting -- local policy
-- user rights assignment -- log on as a batch job
3.双击"log on as a batch job",在这里加入你需要的操作系统user
4.再次在OEM的Host Credentials输入那些user和password,一切ok。
Schedule3:
- BEGIN
- /* Complex scheduling example 1: Public Holidays */
- DBMS_SCHEDULER.CREATE_SCHEDULE
- (schedule_name => 'HR.SCHEDULE3'
- ,repeat_interval =>'freq=YEARLY;bydate=20180607,20180608,20180701'
- ,comments => 'Public Holidays 2015'
- );
- END;
复制代码 Schedule31:
- BEGIN
- /* Complex scheduling example 2: Working Days */
- DBMS_SCHEDULER.CREATE_SCHEDULE
- (schedule_name => 'HR.SCHEDULE31'
- ,repeat_interval =>
- 'freq=YEARLY;byday=MON,TUE,WED,THU,FRI;'
- ,comments => 'Run on every working day'
- );
- END;
复制代码-
- BEGIN
- sys.dbms_scheduler.create_schedule(
- repeat_interval => 'FREQ=yearly;bydate=20181107,20181108,20181201;BYHOUR=14;BYMINUTE=10;BYSECOND=0;exclude=HR.SCHEDULE31',
- start_date => systimestamp at time zone 'Asia/Shanghai',
- schedule_name => '"HR"."SCHEDULE32"');
- END;
复制代码- declare
- v_1 timestamp;
- begin
- for i in 1..1
- loop
- DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
- calendar_string=>'HR.SCHEDULE32' ,
- start_date => sysdate,
- return_date_after => v_1,
- next_run_date => v_1 );
- dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
- end loop;
- end;
复制代码 Program4:
- CREATE TABLE hr.scheduler_test (
- id NUMBER(10) NOT NULL,
- created_date DATE NOT NULL,
- CONSTRAINT scheduler_test_pk PRIMARY KEY (id)
- );
- CREATE SEQUENCE hr.scheduler_test_seq;
复制代码
- BEGIN
- DBMS_SCHEDULER.CREATE_PROGRAM(
- program_name=>'"HR"."PROGRAM4"',
- program_action=>'BEGIN
- INSERT INTO scheduler_test (id, created_date)
- VALUES (scheduler_test_seq.NEXTVAL, SYSDATE);
- COMMIT;
- END;',
- program_type=>'PLSQL_BLOCK',
- number_of_arguments=>0,
- comments=>'',
- enabled=>TRUE);
- END;
复制代码
Schedule4:
- select * from dba_queues q where q.QUEUE_TYPE='NORMAL_QUEUE' ;
- select * from dba_queues q where q.QUEUE_TYPE='EXCEPTION_QUEUE';
- select * from dba_queues q where q.QUEUE_TYPE
- not in ('NORMAL_QUEUE','EXCEPTION_QUEUE');
-
- CREATE OR REPLACE TYPE t_event_queue_payload AS OBJECT (
- event_name VARCHAR2(30)
- );
- grant execute on t_event_queue_payload to hr;
- BEGIN
- -- Create a queue table to hold the event queue.
- DBMS_AQADM.create_queue_table(
- queue_table => 'event_queue_tab',
- queue_payload_type => 't_event_queue_payload',
- multiple_consumers => TRUE,
- comment => 'Queue Table For Event Messages');
- -- Create the event queue.
- DBMS_AQADM.create_queue (
- queue_name => 'event_queue',
- queue_table => 'event_queue_tab');
- -- Start the event queue.
- DBMS_AQADM.start_queue (queue_name => 'event_queue');
- END;
- select * from dba_queues q where q.QUEUE_TYPE='NORMAL_QUEUE' ;
- select * from dba_queues q where q.QUEUE_TYPE='EXCEPTION_QUEUE';
- select * from dba_queues q where q.QUEUE_TYPE not in ('NORMAL_QUEUE','EXCEPTION_QUEUE');
- begin
- dbms_aqadm.grant_queue_privilege(privilege => 'ENQUEUE',queue_name => 'event_queue',grantee => 'HR');
- end;
-
- begin
- dbms_aqadm.grant_queue_privilege(privilege => 'DEQUEUE',queue_name => 'event_queue',grantee => 'HR');
- end;
- select * from dba_tab_privs p where p.grantee='HR';
复制代码- BEGIN
- sys.dbms_scheduler.create_event_schedule(
- event_condition => 'tab.user_data.event_name = ''give_me_a_prod''',
- queue_spec => '"SYS"."EVENT_QUEUE"',
- start_date => systimestamp at time zone 'Asia/Shanghai',
- schedule_name => '"HR"."SCHEDULE4"');
- END;
复制代码
Job4:
- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB4"',
- program_name => '"HR"."PROGRAM4"',
- schedule_name => '"HR"."SCHEDULE4"',
- job_class => '"DEFAULT_JOB_CLASS"',
- auto_drop => FALSE,
- enabled => TRUE);
- END;
复制代码
下面本来ADT设施的:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 21:39:07 2018
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn / as sysdba
- Connected.
- SQL> grant execute on dbms_aq to hr;
- Grant succeeded.
- SQL>
复制代码- DECLARE
- l_enqueue_options DBMS_AQ.enqueue_options_t;
- l_message_properties DBMS_AQ.message_properties_t;
- l_message_handle RAW(16);
- l_queue_msg sys.t_event_queue_payload;
- BEGIN
- l_queue_msg := sys.t_event_queue_payload('give_me_a_prod');
- DBMS_AQ.enqueue(queue_name => 'sys.event_queue',
- enqueue_options => l_enqueue_options,
- message_properties => l_message_properties,
- payload => l_queue_msg,
- msgid => l_message_handle);
- COMMIT;
- END;
复制代码
|
|