how to email csv file using UTL_MAIL and select statement

I want to select * from emp and then email the data as a csv file using UTL_MAIL.  How?  Thanks.
Who is Participating?
sdstuberConnect With a Mentor Commented:
you can use utl_mail for attachments up to 32K

if you need more than that you must use utl_smtp

Here's an example with code I wrote that generates a csv and emails it including the mime encoding needed to create the attachment
slightwv (䄆 Netminder)Connect With a Mentor Commented:
What part?

There are tons of examples creating a csv in Oracle.  I prefer the XMLAGG method.

Using that, select the csv into a varchar2 variable.  Then add that to the message call in utl_mail.

There are tons of utl_mail examples as well.

Just make a note: utl_mail is limited to 32K for a message body.
ewang1205Author Commented:
The content may be over 32k.  So utl_mail limit 32k for attachment??  
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

slightwv (䄆 Netminder) Commented:
I'm not sure utl_mail even does attachments.  It's a pretty dumbed down utility.

You will need to use utl_smtp and 'roll your own'.  The good news, there are also tons of examples sending emails with attachments using utl_smtp out there as well.

Google around and pick the one you like best.  They are out there.
slightwv (䄆 Netminder) Commented:
And, the xmlagg method of creating a csv returns a clob.  That gives you up to 4 Gig.
ewang1205Author Commented:
ok, I am checking utl_smtp now...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.