SELECT and add to email output

Hi guys,
I'm trying to take records from a table and place them in an email sent to myself. The basic email (without any select statement) works so the issue is in retrieving and including the table data. My code attempt is:
DECLARE
  v_From      VARCHAR2(80) := 'C3.Weekly';
  v_Recipient VARCHAR2(80) := '[email protected]';
  v_Subject   VARCHAR2(80) := 'HKADM C3 Stats Fail - ' || to_char(sysdate,'DD') || ' ' ||
        rtrim(to_char(sysdate,'Month'), ' ') || ' ' || to_char(sysdate, 'YYYY');
  v_Mail_Host VARCHAR2(30) := 'smtp.XXX.com';
  v_Mail_Conn utl_smtp.Connection;
  crlf        VARCHAR2(2)  := chr(13)||chr(10);
  db_fail VARCHAR2(4000);
BEGIN
SELECT DISTINCT TBS_SVC_NAME into db_fail
       FROM hkadm.TBSTAT
       ORDER BY 1;
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
   'Date: '   || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
   'From: '   || v_From || crlf ||
   'Subject: '|| v_Subject || crlf ||
   'To: '     || v_Recipient || crlf ||
   crlf ||
' The following databases failed to commit:');
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
   raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;
/I get the error "ORA-01422: exact fetch returns more than requested number of rows and ORA-06512: at line 11". I then thought that maybe I needed to do a loop over the variable but then it complained about there being a FOR :s Any help appreciated.
Mike

Hi Anurag,
I just tried including a cursor as you have but errors occur. The problem is that I wish to loop in the output with is part of a parameter but I don't know how to go about it. My attempt was as follows for it doesn't like the FOR being included and I assume it doesnt like the semicolon after end loop;:
DECLARE
  v_From      VARCHAR2(80) := 'C3.Weekly';
  v_Recipient VARCHAR2(80) := '[email protected]';
  v_Subject   VARCHAR2(80) := 'HKADM C3 Stats Fail - ' || to_char(sysdate,'DD') || ' ' ||
        rtrim(to_char(sysdate,'Month'), ' ') || ' ' || to_char(sysdate, 'YYYY');
  v_Mail_Host VARCHAR2(30) := 'smtp.XXX.com';
  v_Mail_Conn utl_smtp.Connection;
  crlf        VARCHAR2(2)  := chr(13)||chr(10);
  cursor c1 is SELECT DISTINCT TBS_SVC_NAME
FROM hkadm.TBSTAT
ORDER BY 1;
BEGIN
SELECT DISTINCT TBS_SVC_NAME into db_fail
       FROM hkadm.TBSTAT
       ORDER BY 1;
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
   'Date: '   || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
   'From: '   || v_From || crlf ||
   'Subject: '|| v_Subject || crlf ||
   'To: '     || v_Recipient || crlf ||
   crlf ||
' The following databases failed to commit:' ||
for c in c1 loop
c || '
   ' || crlf ||
end loop;
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
   raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;
/ Edit: I've done it at the start of the begin statement keeping it in a variable and it works now. Thanks
Mike
Edited by: Dird on 29-Jul-2009 01:08

Similar Messages

  • Using ios 7.0.4 can a group email be sent either from icloud or iPhone by a means other than selecting the individual Contact, ie; can the group be selected and then an email composed that will send the message to all group members.

    Using ios 7.0.4 can a group email be sent either from icloud or iPhone by a means other than selecting the individual Contact, ie; can the group be selected and then an email composed that will send the message to all group members.

    Hi Richard, 
    Thanks for the reply - I think I've sorted it though and there isn't actually an issue.
    The whole group wasn't receiving the NDR, only the group manager which I setup a few weeks prior. This is a new feature so it complies with certain RFC's, basically the group manager will recieive the NDR to let them know there is a problem.
    Something to do with mass mailing and unsolicited mail.
    Ta
    Ian

  • Trackpad - select and drag of email address in Mail

    Looks like the normal select and drag behaves differently in mac mail when you are using the email addresses on the CC and To lines ...
    In Mac Mail, When I did a reply-all to an email, it placed the person the email was sent to originally in the CC area - I wanted to drag their email address up to the To: line but couldn't figure out how to do this with the trackpad. When hovering over the email address (which was recognized and shown with their name in an oval shape) I then did a single-touch on the trackpad and held it would bring up a secondary menu rather than letting me then drag it. A single click of the trackpad didn't seem to help either
    Any ideas on how to drag a "recognized" email address from the CC to the To line in mac mail using the trackpad ?
    thanks

    Well, here's a work around ... just as a reminder, when using the mouse, you click and hold and drag to the other line you want the address
    With the trackpad, if I double tap, it converts the oval with their name to their full address. Then if you again double click and hold to (had to do this a couple times to get the whole thing selected) then you can drag with another finger the address between To: and CC: or vice versa
    Several extra clicks needed to do what the mouse did - this should be fun explaining this to the wife
    Perhaps there's an easier way someone can point out ...
    thanks

  • HT5312 I cant call u please help me for reset my security qustions and add rescue email please

    Its several times that i want you to add rescue email and reset my security quistions AND I CANT call now i have ipnone 5S and before this i had iphone 4
    Please help ME

    We are fellow users here on these forums, you're not talking to iTunes Support nor Apple.
    If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will need to contact iTunes Support / Apple in your country to get the questions reset - which will normally be by phone as they need to confirm your id and that it's your account.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset you can then use the steps half-way down this page to add a rescue email address for potential future use : http://support.apple.com/kb/HT5312

  • [Desktop] Select and Add multiple artists or multiple albums to playlist

    Add a way to add an artist and their albums/songs to a playlist, or be able to select multiple albums to add to a playlist.like you can select multiple songs to add to a list. This may have been asked before, but after digging around I couldn't find much on the subject. there are times I find it would be easier just to select multiple artists or albums artist to a playlist instead of just a song. 

    Updated: 2015-08-04Marked as new idea.

  • HT1918 itunes hooked up to an e-mail no longer good tried to chg and add new email but it show system set me up with new account instead of updating new email need to merge and use the current email with old account

    I have had itunes for years, however, old account was setup under [email protected] and I no longer have that e-mail or ATT internet service so everytime I want to update my e-mail account with my new [email protected] it wll not let me because I tried to update from my itues account and just changed the e-mail id field and it allowed me to update however it actually just made me have another seperate account under my current e-mal.
    I need to merge the two how can  I do that now that this system has me as two different accounts. One is Tracy Rucker the other one has all of my names
    Tracy Randle Wlliams Rucker?
    Help please no verication e-mails can be verified with the old sbcglobal.net account

    In iTunes, do Store->View my AppleID
    Click "Deuthorize ALL"
    Then, on any computers you still have, do Store->Authorize this computer.  If there are less than 5, you will have no problem.
    You can only do "deauthorize all" once a year, so in the future, if you ever throw a computer away, remember do to "Store->Deauthorize this computer" first.

  • Can't select and send several emails from outlook to onenote

    I have been successfully using the Send to Onenote button from Outlook when choosing either one email or numerous emails.  However, starting last week, I can no longer choose more than one email and send it to Onenote.  I can choose several emails
    and use the Print To Onenote option, but then all emails are put into a single page in Onenote.  
    I can choose a single email at a time and send that to OneNote with no problem.
    I am running Windows 7 with Service Pack 1, 64 Bit
    Outlook and Onenote are Office Professional Plus 2010 32-bit
    Has anyone else experienced this?  
    Thanks

    The latest fix is in thread "http://answers.microsoft.com/en-us/office/forum/office_2010-outlook/cant-send-multiple-emails-to-onenote/52f276db-5826-49f3-93b5-45f9b5a9e4f7?page=2&rtAction=1386601168018"
    When I removed both KB2794707 and KB2837597 the problem with multiple email send to onenote went away again.  I wish they listed the authors on those fixes.  There may be a code fragment causing this that they keep inserting into newer fixes and
    it would be nice if that would stop.

  • Listbox component, multiple selections and databases

    Hello, I have a listbox component bound to a database. It populates alright, but when I want to set the default selections and add an array of String objects to the listbox's selected property, they never appear selected. I set the array in the prerender method. Has anyone done this before? I searched and only found different situations.
    TIA,
    Scott

    Here is an excerpt from http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/about_components.html
    "One way to preselect items is to call setSelectedValue(Object[]) or setSelectedValue(Object) from the prerender() method. You pass in the return values of the items that you want preselected. ..."
    "For the items property, you specify a display label and a return value for each item in the list. The selected property returns an object, or, if the multiple property is selected, an array of objects, of the same type as the return values. "
    " If the multiple property is false, the value of the component's selected property matches the return value of the selected list item. If the multiple property is set to true (to enable the user to select more than one item), you must bind selected to an array of Object, an array of primitives, or java.util.List. If you use java.util.List, you must specify a converter for the type of the List members unless they are String objects. The array contains values that match the return values of the selected items."

  • [svn:fx-trunk] 10866: Fix broken links in ASDoc comments for TLFTextInput. as and TextArea.as, and add OverrideBase.as to ASDoc output

    Revision: 10866
    Author:   [email protected]
    Date:     2009-10-05 08:56:44 -0700 (Mon, 05 Oct 2009)
    Log Message:
    Fix broken links in ASDoc comments for TLFTextInput.as and TextArea.as, and add OverrideBase.as to ASDoc output
    QE notes: -
    Doc notes: -
    Bugs: -
    Reviewer: -
    Tests run: - checkintests
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/states/OverrideBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/mx/controls/TLFTextInput.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/TextArea.as

    Sorry about that. I am not exactly sure where the problem is, but I know it takes place after I put the <nav> in (in the html portion). If I understand what I am learning, the CSS at the top will structure my html code so I would have thought the CSS tageting my nav would be the focus. Maybe it is a different section though.
    CSS part:
    nav p {
    font-size: 90%;
    color: #FFC;
    text-align: right;
    font-weight: bold;
    background-color: #090;
    padding-top: 5px;
    padding-right: 20px;
    padding-bottom: 5px;
    border-top-width: 2px;
    border-top-style: solid;
    border-top-color: #060;
    HTML part: (bold italic is the part I added)
    <body>
    <div class="container">
      <div id="apDiv1"><img src="Lessons/images/butterfly-ovr.png" width="170" height="158" alt="GreenStart Logo"></div>
      <header></header>
      <nav>
        <p>Home | About Us | Contact Us</p>
      </nav>
      <div class="sidebar1">
        <ul class="nav">
          <li><a href="#">Green News</a></li>
          <li><a href="#">Green Products</a></li>
          <li><a href="#">Green Events</a></li>
          <li><a href="#">Green Travel</a></li>
          <li><a href="#">Green Tips</a></li>
        </ul>

  • How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, how do I select the first and last message and delete everything in between?

    How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.

    I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
    Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
    I'm astounded that there's so little support for such a common issue for which people have been asking for years.

  • Sending email for selected pages of a script output

    Hi all,
    i want to know how to send email only the selected pages of an script output.Example if the script produce 10 pages i want to send 4th and 5th page to one customer and 6th ,7th page to another customer like that. because this is an customer statement of account which is confidetial. i refer so many sites but useless. i hope here my problem can solve.
    rgds,
    Ashok

    Hi ashok,
    While enter the print parameters enter the page number what ever u want.
    Reply for queries,
    Regards,
    Kumar.

  • My iPad has a different Apple ID than the Apple ID on my computer. The iPad Apple ID has an email address that I no longer use. If I try to add the email address that I now use (and which is my Apple ID on the computer), it won't allow me to add it.

    My iPad has a different Apple ID than the Apple ID on my computer. The iPad Apple ID has an email address that I no longer use. If (while on the iPad) I go to My Apple ID and try to change or add the email address that I now use (and which already is my Apple ID on the computer), it won't allow me to add it. It says : "Email address is already verified for another Apple ID"  I haven't really been aware of this as a problem until I tried (for the first time) to sync my iPad to the computer and became aware that certain things wouldn't transfer. What is the solution to this?

    What are you having problems with ?
    This post was about having updated the primary email address on an iTunes account via a computer - if you do that you might need to log out of the account on an iPad by tapping on the id in Settings > iTunes & App Store and then log back in with the updated version of the account for that email address change to be recognised on your iPad. If you don't log out and back in then an iPad (or iPhone or iPod Touch) might continue to show the old version of the iTunes account id.

  • Unable to delete email from trash bin.  How do I do this?  If I select and chose delete, it doesn't.  What am I doing wrong?  My grand daughte is using my iPad and I don't want her to see some of the mail there.

    Unable to delete email from trash bin.  How do I do this?  If I select and chose delete, it doesn't.  What am I doing wrong?  My grand daughte is using my iPad and I don't want her to see some of the mail there.

    There are two ways that should work. When you are in the trash folder, you can swipe on the email in the list - left to right - and a red Delete button should pop up. Or you can select - Edit - at the top of the list of messages and then select the message and tap delete.
    Not sure exactly how this works - but if you have restrictions enabled - especially since you let your grandchild use the device - that may be restricting what you can do in the mail app. Go to Settings>General>Restrictions. If you have it set to on - turn it off or see if you have mail restricted.

  • HT5312 I forgot my security question and my rescue email are the same as Apple ID so cannot reset my security question. Any advice on how to reset m security or add a rescue email ? Thanks

    I forgot my security question and my rescue email are the same as Apple ID so cannot reset my security question. Any advice on how to reset m security or add a rescue email ? Thanks

    If you don't have a rescue email address then you will need to contact iTunes Support / Apple to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset you can use the steps half-way down the HT5312 page that you posted from to add a rescue email address for potential future use

  • I am trying to add my sons email address to our family apple id but it says that it already associated with another apple id. How can i find out what the apple id is and take his email address off that one?

    I am trying to add my sons email address to our family apple id but it says that it already associated with another apple id. How can i find out what the apple id is and take his email address off that one?

    You may be able to find your Apple ID at Look up your old and forgotten Apple ID

Maybe you are looking for

  • Error while creating Adaptive Webservice model

    Hi , I am getting errors when trying to create an adaptive webservice model. I am working in NWDI environment. When i tried to create adaptive webservice model  in local development it was successful. But when i tried to create the same using the com

  • Apple account hacked?

    I wonder if some one can help me. I am a I pad 2 user and recently updated to IOS 6. I never use the Message function on my I pad but a few days a go I tested it and senf and message to the I phone of my husband since I was wondering which account wo

  • Charts across multiple pages

    Hi all,          with Crystal Reports 2008 is it possible for a chart to span multiple pages? We have a bar chart that will have many columns and we would want it to span 2 or more pages. How would you set the chart up to tell it to span multiple pag

  • Customer conversion for Non-English languages

    Hi: We have a requirement to convert customer data from lagacy system to Oracle EBS supporting English and Non-English languages. Our conversion programs for english is working fine but we are not sure about the approach for other language converions

  • Inserting embeded PDF to database

    Hi, I have created a pdf file(a Form) that I would like to put on my website where I could enter the data inside the form's fields, and then save the pdf file to a database(mysql). If it can be done, how would I go about doing it? What I have tried s