Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


automatic email alert

Posted on 2016-11-23
Medium Priority
Last Modified: 2016-11-24
hi experts,

i have two tables. in table1 i have two columns (store,email),in table2 i have two columns (store,logs). In table1 ,for one particular store we have only one email id associated. but in table2 with one particular store we will have multiple logs. What i need to do is i need to send an email to that email id with which the store is attached in table1 and in the body of that email i will have the names of the logs associated with that store in table2. I need to use plsql query for this. please help me with this issue. i have attached the screenshorts of demo tables.

Question by:sam shah
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 74

Accepted Solution

sdstuber earned 2000 total points
ID: 41899087
Do you need to send the file names or the contents of those files?

If the contents, where are the files?
And, should the contents be written into the body of the email, or sent as attachments?

If you only need to send the file names, then something like this should work...

    v_connection   UTL_SMTP.connection;
    FOR e IN (SELECT e.store, e.email
                FROM store_emails e
               WHERE e.store IN (SELECT l.store
                                   FROM store_logs))
        v_connection := UTL_SMTP.open_connection('your.email.server.com');
        UTL_SMTP.helo(v_connection, 'your.domain.com');
        UTL_SMTP.mail(v_connection, 'your_return_address@your.domain.com');
        UTL_SMTP.rcpt(v_connection, e.email);

        UTL_SMTP.write_data(v_connection, 'From: Your Name' || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'To: ' || e.email || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'Subject: Store Logs' || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);

        -- This is easy and likely sufficient for short emails
        -- but, if your email body becomes large
        -- you may want to construct it as a clob before connecting to the email server
        -- then write the clob into the email body so you don't get timeouts
        FOR l IN (SELECT logs
                    FROM store_logs l
                   WHERE l.store = e.store)
            UTL_SMTP.write_data(v_connection, l.logs || UTL_TCP.crlf);
        END LOOP;


Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
A couple of weeks ago, my client requested me to implement a SSIS package that allows them to download their files from a FTP server and archives them. Microsoft SSIS is the powerful tool which allows us to proceed multiple files at same time even w…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question