Ask the Expert

Verifying date columns, sending e-mail with PL/SQL

I need to verify a date column, and if it matches, send an e-mail to my manager with some text in the mail... Can I do it using PL/SQL?

    Requires Free Membership to View

Yes, you can do this. But you'll definitely need PL/SQL and the UTL_SMTP package. Hopefully, the following sample program will give you an idea of what you need to do:

DECLARE
   col_date DATE;
   mailhost VARCHAR2(30):='mailhost.mydomain.com';
   mail_conn  utl_smtp.connection;
BEGIN
   SELECT date_column INTO col_date FROM tableX;
   IF (col_date < TO_DATE('01/01/02','MM/DD/YY')) THEN
      mail_conn := utl_smtp.open_connection(mailhost,
25);
      utl_smtp.helo(mail_conn, mailhost);
      utl_smtp.mail(mail_conn, sender);
      utl_smtp.rcpt(mail_conn, recipient);
      utl_smtp.data(mail_conn, message);
      utl_smtp.quit(mail_conn);
   END IF;
END;
You'll have to supply values sender, recipient and message, which I've ommitted. The Oracle docs on the UTL_SMTP package give you much more detail!

For More Information

  • What do you think about this answer? E-mail the editors at editor@searchDatabase.com with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
  • Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
  • Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.

This was first published in April 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: