Oracle觸發器調用procedure寄信

來源:互聯網
上載者:User

標籤:end   address   begin   不同   pre   sub   htm   app   output   

最近寫了一直Web Service給很多不同站的客戶端呼叫,並直接寄信通知程式中的異常。

直接在oracle中設置某張表的trigger(after insert),當有新的異常資料寫入時候,寄給相關站別的管理員。

 

/* Written by milo on 2017-03-09*觸發器發送email*/CREATE OR REPLACE TRIGGER small_program_exception_afin  AFTER INSERT ON small_program_exception  FOR EACH ROWDECLARE  l_html         VARCHAR2(32767);  v_station_name varchar(300);  v_email_string varchar2(1000);  v_program_name varchar2(300);  v_station_code varchar(300);BEGIN  /*  dbms_output.put_line(‘new.station: ‘ || :new.station);  dbms_output.put_line(‘new.program_id: ‘ || :new.program_id);  dbms_output.put_line(‘new.occurred_time: ‘ ||                       to_char(:new.occurred_time, ‘yyyy-mm-dd hh24:mm:ss‘));  dbms_output.put_line(‘new.program_id: ‘ ||                       substr(:new.exception_message, 1, 32767));  */  BEGIN    --獲取程式名稱、接收人email以及站名稱    select s.stn_name, m.mail_for_error, p.name,s.stn_code      into v_station_name, v_email_string, v_program_name,v_station_code      from tk_cust_prog_m m, tk_cust_prog_d d, station s, tk_programe p     where m.custom_no = d.custom_no       and m.custom_no = s.stn_code       and d.prog_id = p.id       and d.prog_id = :new.program_id       and d.custom_no = :new.station;  exception    when no_data_found then      raise_application_error(-20001, ‘No data found.‘);      --dbms_output.put_line(‘no_data_found‘);      --dbms_output.put_line(‘v_email_string: ‘ || v_email_string);      if (v_email_string is null or v_email_string = ‘ ‘) then        raise_application_error(-20001,                                ‘Errors email recipient should not be empty, please type the recipient‘‘s email address on the web-function‘);      end if;  END;  l_html := ‘<html><head>    <title></title></head><body><p> Dear ‘ || v_station_code || ‘</p><p> This email is to notify you that an unexpected error occurred in the program. Please check it ASAP.</p><p> Exception Message</p><p> ------------------------------------------------------------------------------</p><p> <b>‘ || v_station_name || ‘</b></p><p> <b>‘ || v_program_name || ‘</b></p><p> Posted on ‘ ||            to_char(:new.occurred_time, ‘mm-dd-yyyy hh24:mm:ss‘) || ‘</p><p> ‘ || substr(:new.exception_message, 1, 32767) || ‘</p><p> ------------------------------------------------------------------------------</p></body></html>‘;  send_mail(p_to        => v_email_string,            p_from      => ‘[email protected]***.com‘, -- ***@oecgroup.com            p_subject   => ‘Program Occurred Errors Notice‘,            p_text_msg  => ‘‘,            p_html_msg  => l_html,            p_smtp_host => ‘spam.***.com‘,             p_account   => ‘[email protected]***.com‘,             p_password  => ‘***‘); END;/

 

Oracle觸發器調用procedure寄信

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.