I am trying to create a procedure that accomplishes the following: 1) Queries USER_JOBS for any broken or failing jobs and 2) emails the query output.
I have both the logic for the two separates parts of this, but am having trouble incorporating them.
1)USER_JOBS query:
SELECT job
,failures
,broken
,what job_definition
FROM
user_jobs
WHERE
broken = 'Y' OR NVL(failures,0) > 0
ORDER BY job ;
2) Email script:
DECLARE
v_connection UTL_SMTP.CONNECTION;
BEGIN
v_connection := UTL_SMTP.OPEN_CONNECTION(mailhost,25);
UTL_SMTP.HELO(v_connection,mailhost);
UTL_SMTP.MAIL(v_connection,'sender@domain');
UTL_SMTP.RCPT(v_connection,'recipient@domain');
UTL_SMTP.DATA(v_connection,'This is a test...sent from Oracle');
UTL_SMTP.QUIT(v_connection);
END;
I can run both of these successfully, however don't really know where to start in attempting to incorporate the two into a script/procedure that will email the results of the query.
Thanks for any suggestions you can offer!
I have both the logic for the two separates parts of this, but am having trouble incorporating them.
1)USER_JOBS query:
SELECT job
,failures
,broken
,what job_definition
FROM
user_jobs
WHERE
broken = 'Y' OR NVL(failures,0) > 0
ORDER BY job ;
2) Email script:
DECLARE
v_connection UTL_SMTP.CONNECTION;
BEGIN
v_connection := UTL_SMTP.OPEN_CONNECTION(mailhost,25);
UTL_SMTP.HELO(v_connection,mailhost);
UTL_SMTP.MAIL(v_connection,'sender@domain');
UTL_SMTP.RCPT(v_connection,'recipient@domain');
UTL_SMTP.DATA(v_connection,'This is a test...sent from Oracle');
UTL_SMTP.QUIT(v_connection);
END;
I can run both of these successfully, however don't really know where to start in attempting to incorporate the two into a script/procedure that will email the results of the query.
Thanks for any suggestions you can offer!