The following lines contain the word 'select', 'insert', 'update' or 'delete':
G_created_updated_by NUMBER:=TO_NUMBER (FND_PROFILE.VALUE('USER_ID')) ;
G_LAST_UPDATE_LOGIN NUMBER:=TO_NUMBER (FND_PROFILE.VALUE('LOGIN_ID') ) ;
SELECT IEM_RT_PP_QUEUES_s1.nextval
INTO l_seq_id
FROM dual;
INSERT INTO IEM_RT_PP_QUEUES
(
EMAIL_ID,
MSG_UID,
EMAIL_ACCOUNT_ID,
SUBJECT,
FROM_ADDRESS,
MSG_SIZE ,
FLAG,
RETRY_COUNT,
ACTION,
RFC822_MESSAGE_ID,
RECEIVED_DATE,
CREATED_BY,
CREATION_DATE,
LAST_UPDATED_BY,
LAST_UPDATE_DATE,
LAST_UPDATE_LOGIN
)
VALUES
(
l_seq_id,
p_msg_uid,
p_email_acct_id,
p_subject,
p_from,
p_size,
p_flag,
p_retry_count,
l_action,
substr(p_rfc822_msgId,1,256), -- Fix for bug 6633789
p_received_date,
decode(G_created_updated_by,null,-1,G_created_updated_by),
sysdate,
decode(G_created_updated_by,null,-1,G_created_updated_by),
sysdate,
decode(G_LAST_UPDATE_LOGIN,null,-1,G_LAST_UPDATE_LOGIN)
);
INSERT INTO IEM_RT_PP_QUEUE_DTLS
(
EMAIL_ID,
ATTACHMENT_NAME,
ATTACHMENT_SIZE,
ATTACHMENT_TYPE,
CREATED_BY,
CREATION_DATE,
LAST_UPDATED_BY,
LAST_UPDATE_DATE,
LAST_UPDATE_LOGIN
)
VALUES
(
l_seq_id,
p_attach_name_tbl(i),
decode(p_attach_size_tbl(i), null, 0, to_number(p_attach_size_tbl(i))),
p_attach_type_tbl(i),
decode(G_created_updated_by,null,-1,G_created_updated_by),
sysdate,
decode(G_created_updated_by,null,-1,G_created_updated_by),
sysdate,
decode(G_LAST_UPDATE_LOGIN,null,-1,G_LAST_UPDATE_LOGIN)
);
for x in ( select email_id
from IEM_RT_PP_QUEUES
where flag = 'N' and retry_count < 5
order by creation_date)
LOOP
BEGIN
select * into l_queue_rec from IEM_RT_PP_QUEUES
where email_id=x.email_id and flag = 'N' FOR UPDATE NOWAIT;
update IEM_RT_PP_QUEUES set flag ='A', retry_count=retry_count+1 where email_id=l_queue_rec.email_id;
delete IEM_RT_PP_QUEUE_DTLS where email_id in
( select email_id from iem_rt_pp_queues where flag = 'S'
and email_account_id=p_acct_id );
delete IEM_RT_PP_QUEUES where flag = 'S' and email_account_id=p_acct_id ;
for y in ( select email_account_id, count(*) total,
nvl(max(sysdate-creation_date),0) wait_time
from IEM_RT_PP_QUEUES
where flag = 'N' and retry_count < 5
group by email_account_id order by wait_time desc )
loop
l_acct_id := y.email_account_id;
FOR x in ( select email_id
from IEM_RT_PP_QUEUES
where flag = 'N' and retry_count < 5 and email_account_id=y.email_account_id
order by creation_date)
LOOP
BEGIN
select * into l_queue_rec from IEM_RT_PP_QUEUES
where email_id=x.email_id and flag = 'N' FOR UPDATE NOWAIT;
update IEM_RT_PP_QUEUES set flag ='A', retry_count=retry_count+1
where email_id=l_queue_rec.email_id;
select count(*) into l_count from iem_rt_pp_queues
where EMAIL_ID= p_queue_ids(j) and retry_count > 4;
update iem_rt_pp_queues set flag=p_flag where EMAIL_ID= p_queue_ids(j);
update iem_rt_pp_queues set flag='N' where EMAIL_ID= p_queue_ids(j);
update iem_rt_pp_queues set flag='N' where flag='A' and retry_count<=4;