Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:25:30+00:00 2026-06-01T21:25:30+00:00

I am writing a trigger for an Oracle DB to send an email then

  • 0

I am writing a trigger for an Oracle DB to send an email then update a column for that record acknowledging that the email has been sent. I was advised to create a cursor to fetch each row, then gather the info for the email, send the email, update the record, then repeat in a loop. The code below is what I have so far.

CREATE OR REPLACE TRIGGER  "SEND_EMAIL" 
After INSERT OR UPDATE OF ISSUE_ADDED_TO_ALM ON DB_TABLE FOR EACH ROW

DECLARE
  l_table DB_TABLE%rowtype;
  l_body varchar2(4000);
  l_to_address varchar2(2000);
  l_from varchar2(200);
  l_name varchar2(100);
  l_summary varchar2(1000);
  l_description varchar2(4000);
  l_ALM_ID varchar2(100);
  l_subject varchar2(400);
  l_added_to_alm varchar2(200);
  l_SID varchar2(200);

CURSOR cur_ADDED_TO_ALM IS
select * FROM DB_TABLE where ISSUE_ADDED_TO_ALM = '1' and EMAIL_NOTIFICATION = '0';

BEGIN
OPEN cur_ADDED_TO_ALM;
LOOP
Fetch cur_ADDED_TO_ALM into l_table;
Exit when cur_ADDED_TO_ALM%NOTFOUND;


l_from := 'Data Quality IMS Team';

select ISSUE_REQUESTER into l_SID from DB_TABLE;

select emp_email_name,concat(concat(emp_first_name,' '),emp_last_name) into l_to_address, l_name from telephone_book where emp_id = l_SID;

select ISSUE_SUMMARY,ISSUE_DESCRIPTION,ALM_ISSUE_ID into l_summary, l_description, l_ALM_ID from DB_TABLE where ISSUE_ADDED_TO_ALM = '1' and EMAIL_NOTIFICATION = '0';

l_subject := l_ALM_ID + 'Request has been created.';


l_body :=  '<style type="text/css">
p{font-family: Calibri, Arial, Helvetica, sans-serif;
font-size:12pt;
margin-left:30px;
}
</style>';

l_body := l_body ||  '<p>Your request has been created.</p>';
l_body := l_body ||  '<p>Data Quality Center received the following request:</p>';
l_body := l_body ||  '<p>Request ID: '|| l_ALM_ID ||'</p>';
l_body := l_body ||  '<p>Request Title: '|| l_summary||'</p>';
l_body := l_body ||  '<p>Request Description: '|| l_description||'</p>';

  HTMLDB_MAIL.SEND(
    P_TO        => l_to_address,
    P_FROM      => l_from,
    P_BODY      => l_body,
    P_BODY_HTML => l_body,
    P_SUBJ      => l_subject);


    wwv_flow_mail.push_queue(
   P_SMTP_HOSTNAME => 'mail.sever_name.net',
   P_SMTP_PORTNO => '5'
   );

 END LOOP;

update DB_TABLE set EMAIL_NOTIFICATION = '1' where ALM_ISSUE_ID = l_ALM_ID

IF cur_ADDED_TO_ALM%ISOPEN then
CLOSE cur_ADDED_TO_ALM;
END IF;
 end;

I get the following error:
ORA-04091: table server.DB_Table is mutating, trigger/function may not see it ORA-06512: at “server.SEND_EMAIL”, line 15 ORA-06512: at “server.SEND_EMAIL”, line 18 ORA-04088: error during execution of trigger ‘server.SEND_EMAIL’

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:25:31+00:00Added an answer on June 1, 2026 at 9:25 pm

    I offer these solutions.

    1. You cannot UPDATE the table upon which the trigger is activating. You should instead set the value using :new.EMAIL_NOTIFICATION := 1;
    2. You cannot SELECT the table upon which the trigger is activating. This logically doesn’t make sense. That’s the reason you’re getting a “mutating table” error. The table is changing (mutatiing) and you want to read it, which would produce ambiguous results. DO NOT GO AROUND THIS WITH AN AUTONOMOUS TRANSACTION. Someone somewhere is going to give you this suggestion. That would be digging yourself even deeper into a hole.
    3. There is no need for the explicit cursor. Use an implicit one for clarity and simplicity.

    Overall, this is a terrible idea. For a purpose such as this you really don’t want to do it this way. Think about it, the user does an insert or update and must wait until the database sends all the necessary emails. If there are any exceptions raised in the trigger the transaction fails and you have to roll back.

    Better plans

    1. Have the trigger place the email requests into a table. Have a job that runs frequently to send these emails to the email server in the background so the user doesn’t wait.
    2. Have the trigger place email-like messages into a queue. Have a job that ….
    3. Avoid the trigger completely. Just have a job which identifies these records and ….
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing a row-level trigger in Oracle, I know that you can use the
I'm writing a trigger that will do a cross table update, but I can't
I'm having difficulty writing a trigger that sets the rank column to the max
I have an AFTER INSERT OR UPDATE OR DELETE trigger that I'm writing to
I am interested in writing a trigger that would ignore queries from a specific
I am using SQL Server 2000. I am writing a trigger that is executed
I am writing an instead of trigger for updates that does some auditing and
I am writing a Oracle trigger. This trigger should automatically set the value of
I am writing a trigger that will execute everytime a student completes an exam
I have a Postgres database (9) that I am writing a trigger for. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.