didn't send mail html body in plsql

好久不见. 提交于 2019-12-02 19:04:21

问题


I developed a trigger in plsql, the trigger work but I received 6 mails in the same time. I need just one mail, how I can do it?

CREATE or replace TRIGGER RI 
  AFTER insert or update on ap_supplier_sites_all 
  for each row 

DECLARE 
  x_count NUMBER;

begin

  select count(*) into x_count 
  from rib1 r1,rib2 r2 
  where r1.ATTRIBUTE4=r2.Supplier_RIB; 

  if(x_count > 0) 
  then 
     testrib;--execute SP
  end if;
end;

回答1:


Here's how it goes:

  • trigger fires when you insert or update rows in AP_SUPPLIER_SITES_ALL

    • suppose you ran an update statement which updated 6 rows, something like this in Scott's EMP table:

      update emp set 
        sal = sal * 1.1
        where deptno = 20;
      
  • trigger fires for each of those rows; if there are 6 rows updated, it fires 6 times

  • it calculates number of rows in joined rib1 and rib2 tables

    • is it OK not to reference some "ID" column from ap_supplier_sites_all? Something like

      select count(*) into x_count 
      from rib1 r1, rib2 r2 
      where r1.ATTRIBUTE4 = r2.Supplier_RIB
        and r1.some_id = :new.some_ap_supplier_sites_all_id;      --> this
      
  • if that number is larger than 0, you're executing testrib procedure
    • if it sends an e-mail, then yes - it'll send it 6 times

What to do? Switch to a statement-level trigger (instead of the row-level you currently use) as it fires once per statement, regardless number of rows affected.




回答2:


Hello thank you for your update, below my explications: I created two view rib1 and rib3 rib1 for select the last row inserted or updated, rib3 for all rows with attribute4 not null: create or replace view rib1 as ( select * from ( select p.segment1,p.vendor_name,l.attribute4,l.last_update_date,l.last_updated_by from ap_supplier_sites_all l,apps.ap_suppliers p where p.vendor_id=l.vendor_id order by l.last_update_date desc) where rownum=1) create or replace view rib3 as ( select distinct p.segment1 Supplier_Number,p.vendor_name Supplier_Name,s.attribute4 Supplier_RIB,s.last_update_date Update_Date,p.last_updated_by Update_User from apps.ap_supplier_sites_all s , apps.ap_suppliers p where p.vendor_id=s.vendor_id and s.attribute4 is not null) my trigger is created for sending mail if the attribute4 exists with another suppliers (segment1), i created procedure : testrib for sending email, it work i received only email, but when i called testrib in my trigger i received 6 emails in the same time and all time 6 emails (hasn't any relations with count), count()=2--> 6 emails, count()=11--> 6 emails, i think the issue not in count(*) Thanks in advance,



来源:https://stackoverflow.com/questions/58502926/didnt-send-mail-html-body-in-plsql

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