oracle中的电子邮件程序需要很长时间才能执行

时间:2015-01-01 05:17:23

标签: oracle stored-procedures

我有以下程序,

PROCEDURE SEND_TO_MAILING_LIST
 (P_MAILING_LIST IN VARCHAR2
 ,P_SUBJECT IN VARCHAR2
 ,P_TEXT IN VARCHAR2
 ,P_STATUS OUT NUMBER
 )
 IS
CURSOR mail_cur IS
SELECT  x.forenames||'.'||x.surname||'@xyz.com' mail_alias
FROM    ABC a, XYZ x
WHERE   a.id = x.id
AND a.list_name = 'DEF'
AND     a.id <> 274
Union All
SELECT  x.forenames||'.'||x.surname||'@abc.com' mail_alias
FROM    ABC a, XYZ x
WHERE   a.id = x.id
AND x.list_name = 'DEF'
AND     a.id = 274
Union All
SELECT x.other_to_email mail_alias
FROM    ABC a, XYZ x
AND a.list_name = 'PQR';
BEGIN
p_status := 1;
FOR rec IN mail_cur LOOP
        MAILX(rec.mail_alias, 'TESTING PURPOSE','TESTING','TEST');
END LOOP;
EXCEPTION WHEN OTHERS THEN
p_status  := -1;
END;

执行时需要5分钟才能向所需人员发送电子邮件。单个查询仅产生几行(小于5)

这种延迟可能是什么原因?

1 个答案:

答案 0 :(得分:0)

请尝试以下

SELECT  decode(a.list_name,'DEF',x.forenames||'.'||x.surname||decode(a.id,274,'@abc.com','@xyz.com'), x.other_to_email mail_alias)
mail_alias
FROM    ABC a, XYZ x
WHERE   a.id = x.id
AND a.list_name in ('DEF','PQR');