11-2. E-mailing Output from a Scheduled Job
Problem
You have a scheduled job that runs a stored procedure at a regular interval. The procedure produces output that ordinarily would be sent to the screen via the DBMS_OUTPUT.PUT_LINE
procedure, but since it runs as a nightly batch job, you want to send the output to a distribution list as an e-mail message.
Solution
Save the output in a CLOB
variable and then send it to the target distribution list using the UTL_MAIL.SEND
procedure. For example, suppose you want to audit the employee table periodically to find all employees who have not been assigned to a department within the company. Here's a procedure to do that:
CREATE OR REPLACE PROCEDURE employee_audit AS
CURSOR driver IS -- find ...
Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.