Question

How to put select statement into trigger to send email via UTL_SMTP?

Asked by: silterra

Hi,

Need your help. I am very weak on this. I want to put below output of below sql to my UTL_SMTP send by a  trigger in the code section:

Code:
-------
select * from ETL_ERR_EXT_LOTS_DIM
      where RESULT_RETURN > (select ETL_LEVEL from MON_LEVEL where ETL_TYPE = 'EXT_LOTS_DIM')
      and VERIFY_TIME = (select max(VERIFY_TIME) from ETL_ERR_EXT_LOTS_DIM)
      order by VERIFY_TIME desc;

Output:
--------
VERIFY_TIME        LAST_INPUT_TIME    RESULT_RETURN
------------------ ------------------ -------------
17-Aug-09 14:00:00 17-Aug-09 13:41:28 881

CREATE OR REPLACE TRIGGER ETL_MON.T_LOTMSG_IH_TR
BEFORE INSERT
ON ETL_MON.T_ETL_ERR_LOTMSG 
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
   l_mailhost    VARCHAR2 (64)       := 'mailserver.silterra.com';
   l_from        VARCHAR2 (64)       := 'From@silterra.com';
   l_subject     VARCHAR2 (64)      := 'Alert: Lot Message 2 hours checking!';
   l_to          VARCHAR2 (128)       := 'to@silterra.com';
   l_mail_conn   UTL_SMTP.connection;
 
BEGIN
  l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
  UTL_SMTP.helo(l_mail_conn, l_mailhost);
  UTL_SMTP.mail(l_mail_conn, l_from);
  UTL_SMTP.rcpt(l_mail_conn, l_to);
 
  UTL_SMTP.open_data(l_mail_conn);
 
  UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
 
    UTL_SMTP.write_data(l_mail_conn, 'Please update AN on this.' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, 'xxxx> Alert: Lot Message 2 hours checking! <xxxx' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, 'Send by ETL_MON tringger'|| Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
 
  UTL_SMTP.close_data(l_mail_conn);
 
  UTL_SMTP.quit(l_mail_conn);
END;

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-16 at 23:25:45ID24657322
Tags

Oracle

,

Trigger

,

UTL_SMTP

,

Select

,

PL/SQL

Topics

PL / SQL

,

Oracle Database

,

Oracle 9.x

Participating Experts
3
Points
500
Comments
35

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. UTL_SMTP package
    Did anybody use UTL_SMTP package (Oracle 8.1.6.1.0) to send e-mails? Please, provide me with working code! Thank you in advance.
  2. CC with utl_tcp or utl_smtp
    It is possible to send an email to more then one recipient (CC) with utl_tcp or utl_smtp?
  3. UTL_SMTP and russian language
    Hi! I use UTL_SMTP for sending mails through Oracle 8i 8.1.6 database. That is OK with english language messages. But when I try send messages with russian text inside of message I recieve e-mail with ?????????? instead of russian text. Any help? Serg example: Declare ...
  4. UTL_SMTP
    I need a real life example on how to use UTL_SMTP package to send e-mail from oracle procedure
  5. UTL_SMTP
    What system configuration required for use of utl_smtp on Windows 2000 I'm getting ORA-29278: SMTP transient error: 421 Service not available. Shoulld I asked our system administrator or DBA on any privelegies for use of SMTP server ? I need an example as well.
  6. utl_smtp
    I'm using utl_smtp for sending e-mails from Oracle Procedure. I can't send email if I replace e-amil address with distribution list created under my contacts. When I opened address book I see "MAPIPDL" next to the address book, while singuler e-mail addresses have ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: tomcatkevPosted on 2009-08-17 at 00:49:46ID: 25112218

Not sure I understand yet the intended result.

The trigger is on table named ETL_MON.T_LOTMSG_IH_TR.  Inside this trigger, I don't find any reference to any columns of the table, it appears that the email is generated entirely context insensitive from constant data in the trigger, regardless of what data is in the record being inserted.

The SQL that you want to fire the trigger does not reference the table ETL_MON.T_LOTMSG_IH_TR either.  It just seems really odd to put a trigger on a table, and then not use the content pertaining to the table in the trigger, so that the email this generates better describes the transaction.

But anyway, you can imbed SQL into a trigger, and phrase it like
DECLARE V_RETURN_RESULT;
...
select return_result INTO V_RETURN_RESULT from ETL_ERR_EXT_LOTS_DIM
where ....

 

by: shru_0409Posted on 2009-08-17 at 05:46:58ID: 25113737

CREATE OR REPLACE TRIGGER etl_mon.t_lotmsg_ih_tr
   BEFORE INSERT
   ON etl_mon.t_etl_err_lotmsg
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
DECLARE
   l_mailhost    VARCHAR2(64)       := 'mailserver.silterra.com';
                                         -- OR  server iP '255.255.255.255' ;
   l_from        VARCHAR2(64)       := 'From@silterra.com';
   l_subject     VARCHAR2(64)       := 'Alert: Lot Message 2 hours checking!';
   l_to          VARCHAR2(128)      := 'to@silterra.com';
   l_mail_conn   UTL_TCP.connection;
   rc            INTEGER;
BEGIN
   l_mail_conn := UTL_TCP.open_connection(l_mailhost, 25);
                                   -- open the SMTP port 25 on remote machine
   rc := UTL_TCP.write_line(l_mail_conn, 'HELO ' || l_mailhost);
   rc := UTL_TCP.write_line(l_mail_conn, 'MAIL FROM: ' || l_from || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, 'RCPT TO: ' || l_to);
   rc := UTL_TCP.write_line(l_mail_conn, 'DATA');       -- Start message body
   rc := UTL_TCP.write_line(l_mail_conn, 'Subject: ' || l_subject || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, '');
   rc := UTL_TCP.write_line(l_mail_conn, msg_text);
   rc := UTL_TCP.write_line(l_mail_conn, '.');
   rc := UTL_TCP.write_line(l_mail_conn, 'Please update AN on this.' || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, '' || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn,'xxxx> Alert: Lot Message 2 hours checking! <xxxx'|| CHR(13)                       );
   rc := UTL_TCP.write_line(l_mail_conn, '' || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, '' || CHR(13));
   rc := tl_tcp.write_line(l_mail_conn, 'Send by ETL_MON tringger' || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, '' || CHR(13));
   rc := UTL_TCP.write_line(l_mail_conn, 'QUIT');
   UTL_TCP.close_connection(l_mail_conn);
END;

 

by: silterraPosted on 2009-08-20 at 20:00:55ID: 25148847

Hi All,

Sorry for confusing everyone.

The trigger is working to send mail to alert user when the cronjob run and go result to enter the mention table and it will trigger to send an email to user. But the email is just static email.

I try to the select statement to email but facing error.

select * from ETL_ERR_EXT_LOTS_DIM
     where RESULT_RETURN > (select ETL_LEVEL from MON_LEVEL where ETL_TYPE = 'EXT_LOTS_DIM')
     and VERIFY_TIME = (select max(VERIFY_TIME) from ETL_ERR_EXT_LOTS_DIM)
     order by VERIFY_TIME desc;

Hope you can teach me or let me know whather I can do it or not. I try to read from the web but can't really understand.

 

by: silterraPosted on 2009-08-25 at 22:49:02ID: 25184715

Hi All,

Just a simplify my question.

How to email to my user from Oracle when below event is performed and got output like below. In the email must include the output details.

select * from ETL_ERR_EXT_LOTS_DIM
     where RESULT_RETURN > (select ETL_LEVEL from MON_LEVEL where ETL_TYPE = 'EXT_LOTS_DIM')
     and VERIFY_TIME = (select max(VERIFY_TIME) from ETL_ERR_EXT_LOTS_DIM)
     order by VERIFY_TIME desc;

Output:
--------
VERIFY_TIME        LAST_INPUT_TIME    RESULT_RETURN
------------------ ------------------ -------------
17-Aug-09 14:00:00 17-Aug-09 13:41:28 881  

 

by: nav_kum_vPosted on 2009-08-26 at 20:46:31ID: 25194424

may be somethign like as shown below....

assuming your select statement will return only one record.. try the attached code...

CREATE OR REPLACE TRIGGER ETL_MON.T_LOTMSG_IH_TR
BEFORE INSERT
ON ETL_MON.T_ETL_ERR_LOTMSG 
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
   l_mailhost    VARCHAR2 (64)       := 'mailserver.silterra.com';
   l_from        VARCHAR2 (64)       := 'From@silterra.com';
   l_subject     VARCHAR2 (64)      := 'Alert: Lot Message 2 hours checking!';
   l_to          VARCHAR2 (128)       := 'to@silterra.com';
   l_mail_conn   UTL_SMTP.connection;
 
   temp_var varchar2(1500):=null;
 
BEGIN
 
select VERIFY_TIME || LAST_INPUT_TIME   || RESULT_RETURN
into temp_var
from ETL_ERR_EXT_LOTS_DIM where RESULT_RETURN > (select ETL_LEVEL from MON_LEVEL where ETL_TYPE = 'EXT_LOTS_DIM') and VERIFY_TIME = (select max(VERIFY_TIME) from ETL_ERR_EXT_LOTS_DIM) order by VERIFY_TIME desc;
 
  l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
  UTL_SMTP.helo(l_mail_conn, l_mailhost);
  UTL_SMTP.mail(l_mail_conn, l_from);
  UTL_SMTP.rcpt(l_mail_conn, l_to);
 
  UTL_SMTP.open_data(l_mail_conn);
 
  UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
  UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
 
    UTL_SMTP.write_data(l_mail_conn, 'Please update AN on this.' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, 'xxxx> Alert: Lot Message 2 hours checking! <xxxx' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
-- i have added here so that it gets concatenated into the email text..you can 
-- format it to whatever line you want and where it has to appear. also you can
-- get the column headings into the email text if you want by adding
-- one more static header line just before this line...
	UTL_SMTP.write_data(l_mail_conn, temp_var || Chr(13)); 
 
	UTL_SMTP.write_data(l_mail_conn, 'Send by ETL_MON tringger'|| Chr(13));
	UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
 
  UTL_SMTP.close_data(l_mail_conn);
 
  UTL_SMTP.quit(l_mail_conn);
END;
/

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:

Select allOpen in new window

 

by: silterraPosted on 2009-08-26 at 22:31:11ID: 25194858

Hi nav_kum_v,

Let me try now.

 

by: silterraPosted on 2009-08-26 at 23:12:37ID: 25195032

Hi nav_kum_v,

my cron job have below error:


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
INTO T_ETL_ERR_ATTENDANCE
    *
ERROR at line 3:
ORA-04091: table ETL_MON.T_ETL_ERR_ATTENDANCE is mutating, trigger/function may
not see it
ORA-06512: at "ETL_MON.T_ATTENDANCE_MH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_ATTENDANCE_MH_TR'

 

by: silterraPosted on 2009-08-26 at 23:38:34ID: 25195143

Hi nav_kum_v,

Maybe can you shown me, how you will writte this below event in Oracle

1. Monitoring every 30 minutes and keep ouput in a table: T_ETL_ERR_ATTENDANCE

INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
           Max(msg_state_WHEN) Last_Input,
           TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
           from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. Sent email to user

3. Inside the email contain the ouput .

 

by: silterraPosted on 2009-08-26 at 23:39:16ID: 25195147

Hi All experts,

Please help also.

Thanks.

 

by: silterraPosted on 2009-08-26 at 23:47:53ID: 25195182

Below are the email currently, I can produce:


From: xxxx
Sent: None
To: xxxx

Subject: Alert: ext_lots_dim data lagging!
Please update Aun Nee on this.
xxxx> Alert: ext_lots_dim data lagging! <xxxx
 
Send by ETL_MON tringger
 
Bcc:
Return-Path: DIST-IT-ETLMON@silterra.com
Message-ID: <MYITEX01FntS72ebejm0004d254@MYITEX.silterra.com>
X-OriginalArrivalTime: 27 Aug 2009 06:00:04.0595 (UTC) FILETIME=[9F4F5430:01CA26DB]
Date: 27 Aug 2009 14:00:04 +0800

 

by: nav_kum_vPosted on 2009-08-26 at 23:56:54ID: 25195220

can u give me the exact/complete trigger code which gave the below error..

<<Hi nav_kum_v,
my cron job have below error:

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
INTO T_ETL_ERR_ATTENDANCE
    *
ERROR at line 3:
ORA-04091: table ETL_MON.T_ETL_ERR_ATTENDANCE is mutating, trigger/function may
not see it
ORA-06512: at "ETL_MON.T_ATTENDANCE_MH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_ATTENDANCE_MH_TR'
>>

 

by: nav_kum_vPosted on 2009-08-26 at 23:59:12ID: 25195230

i am not sure what is the below code because the code what i gave you is trigger code which does not contain the below code...

Pls. let us deal one issue at a time here otherwise everyone will be confused.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Hi nav_kum_v,

Maybe can you shown me, how you will writte this below event in Oracle

1. Monitoring every 30 minutes and keep ouput in a table: T_ETL_ERR_ATTENDANCE

INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
           Max(msg_state_WHEN) Last_Input,
           TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
           from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';


2. Sent email to user

3. Inside the email contain the ouput
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

by: silterraPosted on 2009-08-27 at 00:12:34ID: 25195307

Hi nav_kum_v,

Item 1 is the event which fire the trigger to sent the email.


1. Cron job monitoring every 30 minutes and keep ouput in a table: T_ETL_ERR_ATTENDANCE

INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
           Max(msg_state_WHEN) Last_Input,
           TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
           from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. Trigger to sent email to user:

2.1. Inside the email contain the ouput .

 

by: nav_kum_vPosted on 2009-08-27 at 00:24:53ID: 25195362

ok..if that is the case, then have the trigger to select from this table T_ETL_ERR_ATTENDANCE instead of the select which i had put in there in the trigger code and then give it a try.

but just ensure your select statement should retrieve only one record when you query T_ETL_ERR_ATTENDANCE

let me know if you need help with the code or if you get some error.

if you get any error, please paste both the complete code which gave the error and the error as well.

 

by: tomcatkevPosted on 2009-08-27 at 01:06:39ID: 25195579

I have what might be a simpler way to do this.  Assuming you have a CRON JOB on a Unix platform that does some ETL, and as a final step you want it to send you, or some person or distribution list some info on the results.

And assuming that sendmail is working from that platform, then you may simply add a few lines to the end of the cron job, something like this in a bourne shell / korn shell or bash shell...

sqlplus $connectstr @check_etl > check_etl.out
(
echo "From: Barack.Obama@whitehouse.gov"
echo "Subject: ETL Results"
echo " "
cat check_etl.out
) | mail -tw silterra@yahoo.com

And of course you can put some name other than Barack, so in case the person who gets this email needs to reply to someone, you can put the person responsible for the ETL or answering question about what the message means there.

And of course if you want to imbed other logs, such as sql*loader log, it may also be helpful.  I generally try to do this with multiple layers where I have a simple/summary email that goes to larger distribution with short message, like just row counts loaded and success/failure, and then a more detailed log that goes to selected developer/power user types that have a need to look into the details of what failed.

 

by: nav_kum_vPosted on 2009-08-27 at 01:16:16ID: 25195622

Since the asker is already having the pl/sql code which is already sending the email but just he wanted to add some little more text which is nothing but the output of some sql statement and hence i think he can stick to the same method otherwise he may have to get the unix script working from scratch ( though he has cron entry )  ....

anyways, it is his choice on which method he wants..

 

by: silterraPosted on 2009-09-03 at 03:32:24ID: 25249213

Hi all,

Still can resolve the mutation error:


SQL*Plus: Release 9.2.0.5.0 - Production on Thu Sep 3 18:22:55 2009
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production

1 row created.

1 row created.
INTO T_ETL_ERR_EXT_LOTS_DIM
    *
ERROR at line 3:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "ETL_MON.T_EXT_LOTS_DIM_IH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_EXT_LOTS_DIM_IH_TR'
 
1 row created.

Commit complete.
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production
$

 

Please help

 

by: silterraPosted on 2009-09-03 at 03:40:38ID: 25249256

Hi All,

After rethink, can anyone of you teach me how to read a trigger to fire function (which can send email)?

 

by: nav_kum_vPosted on 2009-09-03 at 03:48:09ID: 25249294

if you get any error, please paste both the complete code which gave the error and the error as well. --> i already put that in my last update itself.

If we need help, then at least i need that info. to understand what code you are executing to get that error.

 

by: nav_kum_vPosted on 2009-09-03 at 03:50:19ID: 25249304

see the error there which you had got ---> "ORA-01422: exact fetch returns more than requested number of rows"  <<<<< for this also i had already put something in my last update itself >>> "but just ensure your select statement should retrieve only one record when you query T_ETL_ERR_ATTENDANCE "

attach the full code here and i can help... it should be simple, some select is returning more than 1 record to give that error.

 

by: silterraPosted on 2009-09-03 at 03:54:39ID: 25249323

1. Cronjob at HP-UX running this sql:

INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
           Max(msg_state_WHEN) Last_Input,
           TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
           from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. Trigger at T_ETL_ERR_ATTENDANCE:


CREATE OR REPLACE TRIGGER ETL_MON.EALERT_ATTENDANCE_TR
AFTER INSERT
ON ETL_MON.T_ETL_ERR_ATTENDANCE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
l_mailhost VARCHAR2 (64) := 'xxxxx.s.com';
l_from VARCHAR2 (64) := 'xxxxx@s.com';
l_subject VARCHAR2 (64) := 'Alert: Attendance ETL down!';
l_to VARCHAR2 (128) := 'xxxxx@s.com';
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
UTL_SMTP.write_data(l_mail_conn, 'Please update Aun Nee on this.' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'xxxx> Alert: Attendance ETL down! <xxxx' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Send by ETL_MON tringger'|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;

 

3. Now want to put the inserted result in the email show the reader can understand what is going on. Instead of fix email.

 

by: nav_kum_vPosted on 2009-09-03 at 04:08:23ID: 25249386

ok..now tell me which one gave the below error ...just say 1) or 2 ) from the above.

1 row created.
INTO T_ETL_ERR_EXT_LOTS_DIM
    *
ERROR at line 3:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "ETL_MON.T_EXT_LOTS_DIM_IH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_EXT_LOTS_DIM_IH_TR'
 
1 row created.

CAN U PLS CLARIFY --> there is no commit in the 1) code in the crontab, so how come this trigger can see that inserted data....

 

by: silterraPosted on 2009-09-03 at 09:31:52ID: 25252333

Error happen at  1 after add in the select statement in item 2.

 

by: silterraPosted on 2009-09-03 at 17:36:45ID: 25256172

Below are the new code:


1. Cronjob at HP-UX running this sql:
INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
           Max(msg_state_WHEN) Last_Input,
           TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
           from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. After update new change on trigger:


CREATE OR REPLACE TRIGGER ETL_MON.T_EXT_LOTS_DIM_IH_TR
AFTER INSERT
ON ETL_MON.T_ETL_ERR_EXT_LOTS_DIM
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
V_RETURN_RESULT VARCHAR2 (888) :=null;
l_mailhost VARCHAR2 (64) := 'xxxxx.silterra.com';
l_from VARCHAR2 (64) := xxxxx@silterra.com';
l_subject VARCHAR2 (64) := 'Alert: ext_lots_dim data 2 hours checking! ';
l_to VARCHAR2 (128) := xxxxxx@silterra.com';

l_mail_conn UTL_SMTP.connection;
BEGIN
select VERIFY_TIME || LAST_INPUT_TIME || RESULT_RETURN
into V_RETURN_RESULT
from T_ETL_ERR_EXT_LOTS_DIM
where VERIFY_TIME LIKE TO_DATE(sysdate, 'DD-MM-YYYY');

l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);

UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
UTL_SMTP.write_data(l_mail_conn, 'Please update Aun Nee on this.' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'xxxx> Alert: ext_lots_dim data 2 hours checking! <xxxx' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Send by ETL_MON tringger'|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, V_RETURN_RESULT || Chr(13));
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;

Below error shown:

INTO T_ETL_ERR_EXT_LOTS_DIM
    *
ERROR at line 3:
ORA-04091: table ETL_MON.T_ETL_ERR_EXT_LOTS_DIM is mutating, trigger/function
may not see it
ORA-06512: at "ETL_MON.T_EXT_LOTS_DIM_IH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_EXT_LOTS_DIM_IH_TR'

 

by: nav_kum_vPosted on 2009-09-03 at 19:04:38ID: 25256469

be consistent in what you are saying. i am getting confused because just before this update you told you are getting the error

"INTO T_ETL_ERR_EXT_LOTS_DIM
    *
ERROR at line 3:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "ETL_MON.T_EXT_LOTS_DIM_IH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_EXT_LOTS_DIM_IH_TR' "

but now you are saying

"INTO T_ETL_ERR_EXT_LOTS_DIM
    *
ERROR at line 3:
ORA-04091: table ETL_MON.T_ETL_ERR_EXT_LOTS_DIM is mutating, trigger/function
may not see it
ORA-06512: at "ETL_MON.T_EXT_LOTS_DIM_IH_TR", line 12
ORA-04088: error during execution of trigger 'ETL_MON.T_EXT_LOTS_DIM_IH_TR'"

Not sure why everytime you change the update which is confusing to everybody who are trying to help you out ?

also please help to provide your comment to the question/info. requested from you which i had put in my prev. update.

CAN U PLS CLARIFY --> there is no commit in the 1) code in the crontab, so how come this trigger can see that inserted data.... ? you never commented for this. I am confused because one session is trying to insert into some table from crontab and it does not have commit.. how come the other session can read the data inserted into this table.. a very basic thing is missing here.. can you comment.

 

by: silterraPosted on 2009-09-03 at 19:29:01ID: 25256531

Hi nav_kum_vi,

You are right!

Missing commit.

Let me try.

 

by: nav_kum_vPosted on 2009-09-03 at 21:03:58ID: 25256766

also reply to this one...

T_ETL_ERR_ATTENDANCE --> you are inserting into this table from crontab ( assuming you have a commit as well there ), but i do not see a select statement to this table in your trigger code -> why is it so ?

as per your earlier updates, you told the data inserted by the crontab script will be used by the trigger code to select from that table and send in the form of an email.

 

by: silterraPosted on 2009-09-03 at 21:42:26ID: 25256896

Hi nav_kumar_v,

Myself also confusing.

I changing flow.

1. Cronjob remain (Create event)

2. Trigger call function (Create new trigger to call function only)

3. Function to email (select and send email)

Hope it work.

 

by: tomcatkevPosted on 2009-09-04 at 22:41:43ID: 25265070

1. Cronjob at HP-UX running this sql:

INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
Max(msg_state_WHEN) Last_Input,
TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. Trigger at T_ETL_ERR_ATTENDANCE:


CREATE OR REPLACE TRIGGER ETL_MON.EALERT_ATTENDANCE_TR
AFTER INSERT
ON ETL_MON.T_ETL_ERR_ATTENDANCE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
l_mailhost VARCHAR2 (64) := 'xxxxx.s.com';
l_from VARCHAR2 (64) := 'xxxxx@s.com';
l_subject VARCHAR2 (64) := 'Alert: Attendance ETL down! '||:new.verify_time||' '||:new.last_input||' '||:new.Result_Return;
l_to VARCHAR2 (128) := 'xxxxx@s.com';
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));

UTL_SMTP.write_data(l_mail_conn, 'Please update Aun Nee on this.' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'xxxx> Alert: Attendance ETL down! <XXXX'
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' ||:new.verify_time|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' ||:new.last_input|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' ||:new.Result_Return|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Send by ETL_MON tringger'|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));

UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;



3. Now want to put the inserted result in the email show the reader can understand what is going on. Instead of fix email.

OK, for this I add a few lines to code above to illustrate, adding content to both subject and in the body of the email. (In my experience, if the intent is to generate a "cell/text/pager message", then a short Subject line <150 chars that contains the whole message is the most desired solution),.

In doing this I assume the above code was working without error, and you just need to add code in the trigger to utilize the columns in the table, which may be prefixed by :NEW. to identify the data elements being added in an INSERT trigger.

l_subject VARCHAR2 (64) := 'Alert: Attendance ETL down! '||:new.verify_time||' '||:new.last_input||' '||:new.Result_Return;

UTL_SMTP.write_data(l_mail_conn, '' ||:new.verify_time|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' ||:new.last_input|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' ||:new.Result_Return|| Chr(13));

 

by: silterraPosted on 2009-09-05 at 20:13:35ID: 25268637

Hi,

Here is the select statement:


Select * from ETL_ERR_ATTENDANCE
where RESULT_RETURN > (select ETL_LEVEL from MON_LEVEL where ETL_TYPE = 'ATTENDANCE')
and VERIFY_TIME LIKE TO_DATE(sysdate, 'DD-MM-YYYY')
order by VERIFY_TIME desc;

 

Below are the example output:

VERIFY_TIME,LAST_INPUT_TIME,RESULT_RETURN
06-Sep-09 11:00:00,05-Sep-09 00:02:40,  2097
06-Sep-09 10:00:01,05-Sep-09 00:02:40,  2037
06-Sep-09 09:00:01,05-Sep-09 00:02:40,  1977
06-Sep-09 08:00:01,05-Sep-09 00:02:40,  1917
06-Sep-09 07:00:00,05-Sep-09 00:02:40,  1857
06-Sep-09 06:00:01,05-Sep-09 00:02:40,  1797
06-Sep-09 05:00:00,05-Sep-09 00:02:40,  1737
06-Sep-09 04:00:00,05-Sep-09 00:02:40,  1677
06-Sep-09 03:00:01,05-Sep-09 00:02:40,  1617
06-Sep-09 02:00:01,05-Sep-09 00:02:40,  1557
06-Sep-09 01:00:00,05-Sep-09 00:02:40,  1497
06-Sep-09,05-Sep-09 00:02:40,  1437

 

by: silterraPosted on 2009-09-06 at 18:37:42ID: 25272308

YES, YES, YES, tomcatkev.

This is what I wanted. Just one more help, how to include time for:

||:new.verify_time||' '||:new.last_input||'

Below are the result of email sent:


Subject: Alert: Attendance ETL down! 07-SEP-09 07-SEP-09 6
Date: 07-SEP-2009 09:30:00
Please update Aun Nee on this.
xxxx> ETL Monitoring Alert: Attendance ETL Lagging! <xxxx
07-SEP-09
07-SEP-09
6
Sent by: ETL_MON tringger

 

by: silterraPosted on 2009-09-06 at 19:27:59ID: 25272468

Finally work.

Below are the completed coding to share:

1. Cron job to create insert event:
INSERT
INTO T_ETL_ERR_ATTENDANCE
select sysdate Verify_Time,
Max(msg_state_WHEN) Last_Input,
TO_CHAR((sysdate - Max(msg_state_WHEN)) * 1440, 99999) Result_Return
from mybus.myom_mybus om, mybus.myoq_mybus oq
where om.mid = oq.mid
and msg_name like 'attendance';

2. trigger to send email:


CREATE OR REPLACE TRIGGER ETL_MON.TEST_EALERT_ATTENDANCE_TR
AFTER INSERT
ON ETL_MON.T_ETL_ERR_ATTENDANCE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
l_mailhost VARCHAR2 (64) := 'MYITEX.s.com';
l_from VARCHAR2 (64) := 'm@s.com';
l_to VARCHAR2 (128) := 'm@s.com';
l_subject VARCHAR2 (64) := 'Alert: Attendance ETL down! Now lagging: '||:new.Result_Return;
DF_Last_Input_Time VARCHAR2 (20);

l_mail_conn UTL_SMTP.connection;
BEGIN
DF_Last_Input_Time :=to_char(:new.LAST_INPUT_TIME,'DD-MON-YYYY HH24:MI:SS');

l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Please update ETL admin on this.' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Verify Date & Time: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Last Update Time: ' ||DF_Last_Input_Time|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Lagging: ' ||:new.Result_Return|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Sent by: ETL_MON tringger'|| Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));
 
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;
 

3. Email output wanted:


Subject: Alert: Attendance ETL down! Now lagging: 7
Please update ETL admin on this.
 
Verify Date & Time: 07-SEP-2009 10:19:41
Last Update Time: 07-SEP-2009 10:13:07
Lagging: 7
 

Sent by: ETL_MON tringger

 

by: silterraPosted on 2009-09-06 at 19:30:54ID: 31616425

Thank you. You had understand my problem.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...