Best way to receive an email after concurrent failed (sql - trigger - application)

我与影子孤独终老i 提交于 2019-12-11 15:51:50

问题


I want to receive an email if the concurrent execution endded up with an error;

Take a look: i have a query which contains the latest execution of a concurrent (i am using Oracle 11g):

select *
  from
  (
    select yer.user_murcurrent_program_yere program,
           mur.request_id "request id",
           mur.status_code status,
           row_number() over (partition by yer.user_murcurrent_program_yere order by mur.request_id desc ) as rn
      from fnd_murcurrent_programs_tl yer
      join fnd_murcurrent_requests mur
        on mur.murcurrent_program_id=yer.murcurrent_program_id
      join fnd_user us
        on mur.requested_by = us.user_id
     where mur.actual_start_date >= date'2019-11-20' 
       and mur.actual_start_date <  date'2019-11-23' + 1
       and (yer.user_murcurrent_program_yere like 'Report sales')   
   )                                         
where rn = 1;

This query returns something like this:

|   program  |request_id|status |
|Report sales|5878547894|WARNING|

In this case i would like to recieve an email saying:

The concurrent "Report sales" with rquest_id '5878547894' endded with status WARNING

These are the possible status:

WARNING,ERROR, STAND BY, RUNNING, COMPLETE

I only want to receive the email if the status is: WARNING, ERROR or STAND BY.

How can i do that? What application should i do or create?. I need to do that and i'm pretty lost.

Could you please help me?


回答1:


You can use double pipes(||) as concatenation operators, and filter the results out by your desired status types listed within parentheses after the IN operator for the query.

Create a procedure and take your query into it as a cursor and use utl_http package within that procedure as below :

create or replace procedure pr_mail_me is

  v_email varchar2(100) := 'my.email@xmail.com';
  v_rep   varchar2(4000);
  v_url   varchar2(4000);

  cursor crs_request is
  select 'The concurrent '||program||' with request_id '||request_id||' ended with status '|| 
           status as message, request_id
    from
    (
       <the subquery>
      )
   where rn = 1
     and status in ('WARNING','ERROR','STAND BY');    

begin

  for c in crs_request
  loop
  begin

    v_url := 'http://www.mycompany.com/path_to/default.aspx?email=' ||
              v_email ||'&out_message='||c.message||'&out_request_id='||c.request_id;
    v_rep := utl_http.request(utl_url.escape(v_url,false,'UTF-8'));

   exception
       when others then
            v_url := 'http://www.mycompany.com/path_to/default.aspx?email=' ||
                      v_email ||'&out_message='||substr(sqlerrm,1,250)||'&out_request_id='||c.request_id;
                      v_rep := utl_http.request(utl_url.escape(v_url,false,'UTF-8'));
        end;
  end loop;
end;

in order to receive e-mails as calling this procedure.



来源:https://stackoverflow.com/questions/59021859/best-way-to-receive-an-email-after-concurrent-failed-sql-trigger-applicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!