« Part Two - E-mail Oracle query results in a spreadsheet | Main
Saturday
Oct162010

Part One - E-mail Query Results in Message Body

I have another post under the "Oracle" section that deals with sending e-mails with results of Jobs that have been scheduled in Oracle Enterprise Manager.  That should suffice for anyone trying to send the results of a single row of a query, but what about queries that return multiple rows of output?

I found a quick-and-dirty way of sending query results spanning multiple rows via e-mail using the built-in tools provided with Oracle. 

The following query sample shows you how to create a PL/SQL "collection" (read:  array) of the VARCHAR2 datatype.  Assuming your query results fit into the maximum size that you can allocate for a variable of this type you should be good to go.  Really I would think that the maximum size restrictions imposed upon e-mail messages in your organization would kick in before you reached the size limitations of the variable, but tentatively try this out and see if it doesn't fit your needs.

I've included a non-funtional sample query to demonstrate how you need to organize your columns.

I assume that when the query results you're sending e-mail notifications out on will sometimes return no rows and you'll want to format the body of the e-mail differently based on that (i.e. why have column headers in the body of the message if there are no rows returned?).

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>