--1.smtp_out_server text 以sysdba身份登录,修改对应的parameter参数值。
Alter System Set SMTP_OUT_SERVER='smtp.server.com' Scope=Spfile;
表示ORACLE安装的宿主目录
@? /rdbms/Admin/utlmail.Sql
@?/rdbms/Admin/prvtmail.plb
--2.windowns对应执行SQL
@?\rdbms\Admin\utlmail.Sql;
@?\rdbms\Admin\prvtmail.plb;
--3重启ORACLE ,修改PARAMETER的参数才会生效
Shutdown Immediate;
startup;
--查看对应参数是否已经正确修改成功
Show parameter smtp;
--4.编写不带附件的send发送邮件样例
Begin
utl_mail.send('otn@oracle.com',
'user@oracle.com',
message=>'For latest downloads visit chenjian',
subject=>'weihong successed');
End;
--4.1。编写带附件(图片)的发送邮件样例
Create Or Replace Procedure send_mail_logo Is
Begin
utl_mail.send_attach_raw(
sender=>'cj@126.com',
recipients=>'you@126.com',
message=>'see attach',
subject=>'test',
mime_type=>'text/html'
attachement=>'oracle.gif',
att_inline=>True,
att_mime_type=>'image/gif',
att_filename=>'test.gif'
);
End;
/
--4.2编写带附件(普通文本的)发送邮件样例
create or replace procedure send_mail_file is
begin
utl_mail.send_attach_varchar2(
sender=>'mymail@oracle.com',
recipients=>'you@oracle.com',
message=>'test',
subject=>'hello',
mime_type=>'text/html',
attachement=>('text.txt'),
att_inline=>false
att_mime_type=>'text/plain',
att_filename=>'text.txt',
);
end;
/
--任务与作业调度
--PLSQL_BLOCK,STORED_PROCEDURE,EXECUTABLEO OPERATION COMMAND
1.用CREATE_JOB方式建立作业任务,repeat_interval重复操作的时间间隔参考本页末说明:
应该块什么都不做,只是为了演示对应的用法
Begin
dbms_scheduler.create_job(
'job_name'=>'test_name',
job_type=>'PLSQL_BLOCK',
job_action=>'begin ..;end;',
start_time=>systimestamp,
repeat_interval=>'FREOUENCY=HOURLY;INTERVALU=1',
Enable=>True);
End;
/
2.通过PROGRAM方式建立作业,
Begin
DBMS_SCHEDULER.CREATE_PROGRAM(
program_name=>'prog_name',
program_type=>'PLSQL_BLOCK',
program_action=>'begin..;end;'
);
End;
/
3.通过JOB与PROGRAM结合来调用一个作业演示的样例
Begin
DBMS_SCHEDULDER.CREATE_JOB('TESTJOB2',
PROGRAM_NAME=>'prog_name',
start_date=>systimestamp,
repeat_interval=>'FREQ=DAILY',
Enable=>True);
End;
/
=========4.EMP_REPORT===============
1.TABLE IS EMP_REPORT
Begin
dbms_scheduler.create_program(
program_name=>'prog_name1',
program_type=>'STORED_PROCEDURE',
program_action=>'EMP_REPORT'
);
End;
/
2.说明:PARAMETER IS dept_id,type:number,value:50
dbms_scheduler.define_program_argument(
program_name=>'PROG_NAME',
argument_name=>'DEPT_ID',
argument_position=>1,
argument_type='NUMBER',
default_value=>'50');
3.对应的传值,对应位置为1
dbms_scheduler.create_job(
'job_name',
program_name=>'PROG NAME',
start_date=>SYSTIMESTAMP,
REPEAT_INTERVAL=>'FREQ=DAILY',
Number Of ARGUMENTS=>1,
Enable=>True
);
End;
dbms_scheduler.set_job_argument_value Change Value From System parameter,
==================================================
5.每天都执行,一直到结束时间15天后;
Begin
dbms_scheduler.create_scheduler('sched_name',
start_date=>systimestamp,
repeat_interval=>'FREQ=DAILY',
END_DATE=>systimestamp+15);
End;
/
6.通过SCHDULER_NAME 来指定相关作业
Begin
dbms_scheduler.create_job('testjob3',
scheduler_name=>'sched_name',
job_type=>'PLSQL_BLOCK',
job_action=>'begin...;end;'
,enabled=>True
);
End;
6.重复的相关时间间隔表示方法有二种,一种是日历法,一种是PL/SQL法;
6.1.
USIG A CALENDARING EXPRESSION
repeat_interval=>'FREQ=HOURLY;INTERVAL=4'
repeat_interval=>'FREQ=DAILY'
repeat_interval=>'FREQ=MINUTELY;INTERVAL=15'
repeat_interval=>'FREQ=YEARLYBYMONTH=MAR,JUN,SEP,DEC;BYMONTHDAY=15'
6.2.
Using A PL/Sql EXPRESSION
repeat_interval=>'SYSDATE+36/24'
repeat_interval=>'SYSDATE+1'
repeat_interval=>'SYSDATE+15/(24*60)'
7.通过指定PROGRAMNAME来创建相应的任务作业
Begin
DBMS_SCHEDULER.CREATE_JOB('JOB_NAME',PROGRAM_NAME=>'PROG_NAME',
SCHEDULE_NAME=>'SCHED_NAME',ENABLED=>True);
End;
8.运行,停止,以及删除相关任务作业
MANAGER JOB Run,Stop,Drop OPERATION
DBMS_SCHEDULER.RUN_JOB('SCHEMA.JOB_NAME');
DBMS_SCHEDULER.STOP_JOB('SCHEMA.JOB_NAME');
DBMS_SCHEDULER.DROP_JOB('SCHEMA.JOB_NAME',True);
9.作业任务调度的数据字典
Desc USER_SCHEDULER_JOBS;
[Dba|All|USER]_SCHEDULER_JOBS
[Dba|All|USER]_SCHEDULER_RUNNING_JOBS
[Dba|All]_SCHEDULER_JOB_CLASSES
[Dba|All|User]_scheduler_JOB_LOG
[Dba|All|User]_scheduler_JOB_RUN_DETAILS
[Dba|All|User]_scheduler_JOB_PROGRAMS
10.主要的catproc.Sql这个Sql来建立相关的包;
对发邮件的ORACLE包UTL_MAIL以及任务作业详细分析