Advertisement
fkeles

PRC_RFRSH_OCI_COST_DATA.sql

May 23rd, 2023 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.52 KB | Source Code | 0 0
  1. CREATE OR REPLACE PROCEDURE PRC_RFRSH_OCI_COST_DATA IS
  2.    l_ctr NUMBER;
  3. BEGIN
  4.     -- check any runnig jobs
  5.     SELECT COUNT(LOG_ID)
  6.       INTO l_ctr
  7.       FROM DBA_SCHEDULER_RUNNING_JOBS  
  8.      WHERE  1=1
  9.        AND job_name LIKE 'PRC_RFRSH_OCI_COST_DATA_JOB%'
  10.        AND SESSION_ID != SYS_CONTEXT('USERENV','SID');
  11.    
  12.     IF l_ctr > 0 THEN
  13.         DBMS_OUTPUT.put_line('there is already a running job');
  14.         RETURN;
  15.     END IF;
  16.        
  17.     --refresh temp table
  18.     DBMS_MVIEW.refresh('OCI_COST_DATA_MV_TMP','C',atomic_refresh=>FALSE);
  19.     DBMS_OUTPUT.put_line('OCI_COST_DATA_MV_TMP refreshed');
  20.    
  21.     --merge insert new rows
  22.     INSERT INTO OCI_COST_DATA_MV
  23.     SELECT t.*
  24.      FROM OCI_COST_DATA_MV_TMP t, OCI_COST_DATA_MV d
  25.     WHERE 1=1
  26.       AND t.REFERENCE_NUMBER = d.REFERENCE_NUMBER(+)
  27.       AND d.REFERENCE_NUMBER IS NULL;
  28.    DBMS_OUTPUT.put_line(SQL%ROWCOUNT||' rows inserted');
  29.    
  30.     IF 1=1 THEN
  31.     -- submit next job for the next hour
  32.     DBMS_SCHEDULER.create_job (
  33.             job_name        => 'PRC_RFRSH_OCI_COST_DATA_JOB_'||SYS_GUID(),
  34.             job_type        => 'PLSQL_BLOCK',
  35.             job_action      => 'BEGIN PRC_RFRSH_OCI_COST_DATA; END;',
  36.             start_date      => SYSTIMESTAMP + INTERVAL '6' HOUR,
  37.             repeat_interval => NULL,--'freq=hourly; byminute=0; bysecond=0;',
  38.             end_date        => NULL,
  39.             enabled         => TRUE,
  40.             comments        => 'Auto-refresh OCI_COST_DATA_MV'
  41.     );
  42.     END IF;
  43. END PRC_RFRSH_OCI_COST_DATA;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement