Tuesday, 25 December 2018

Send an email from APEX Cloud CLOUD_SCHEDULER.create_job

create or replace procedure "PROC_PURGE_MISCELLANEOUS"
is
v_days number(15);
v_legal_id   number(15);
V_COUNTER NUMBER(15):=0;
v_security_group_id number(20);

BEGIN
 SELECT workspace_id   into  v_security_group_id   FROM apex_applications where rownum < 2;


apex_util.set_security_group_id(p_security_group_id =>v_security_group_id    );

for i in (select VARIABLE_VALUE c_days , to_number(DESCRIPTION) C_LEGAL_EMPLOYER_ID   from   CONFIGURATION  where  VARIABLE_CODE like 'PURGE%') loop

select  count(1) into V_COUNTER from EMPREQ_REQUESTS  where LEGAL_EMPLOYER_ID = i.C_LEGAL_EMPLOYER_ID and CREATION_DATE < sysdate - i.c_days;
--delete from EMPREQ_REQUESTS  where LEGAL_EMPLOYER_ID = i.C_LEGAL_EMPLOYER_ID and CREATION_DATE < sysdate - i.c_days;
end loop;

  APEX_Mail.Send( 'm.almasri@Tahaluf.ae', 'm.almasri@Tahaluf.ae',
                  'Number of records got deleted are :'||V_COUNTER,
                  '',
                  'Purging job ....' );
  APEX_Mail.Push_Queue;
END;



--  Send an email from APEX Cloud
BEGIN
  APEX_Mail.Send( 'm.almasri@Tahaluf.ae', 'm.almasri@Tahaluf.ae',
                  'This is some test plain text',
                  'This is some test HTML',
                  'Test Email Subject' );
  APEX_Mail.Push_Queue;
END;
/



-- Creating a job which will run daily at 22:00
BEGIN
  CLOUD_SCHEDULER.create_job (
    job_name        => 'JOB_PURGE_MISCELLANEOUS',
    job_type        => 'PLSQL_BLOCK',
    job_action      => 'BEGIN  PROC_PURGE_MISCELLANEOUS; END;',
    repeat_interval  => 'FREQ=DAILY',   
    start_date => TO_TIMESTAMP_TZ('2018-12-24 22:00:00.000000000 ASIA/MUSCAT','YYYY-MM-DD HH24:MI:SS.FF TZR'),
    enabled         => TRUE);

END;
/


-- Drop existing JOB
BEGIN
  CLOUD_SCHEDULER.DROP_JOB (
     job_name => 'JOB_PURGE_MISCELLANEOUS',
     force    => TRUE);
END;
/


-- Check the status of running jobs
SELECT * FROM USER_SCHEDULER_JOB_RUN_DETAILS WHERE JOB_NAME = 'JOB_PURGE_MISCELLANEOUS';


No comments:

Post a Comment

Number of Visitors