9 Jan 2014

DBMS_JOB EXAMPLE

Following are the example of DBMS_JOB, you can used this proceudre in DBMS_SCHEDULER also
with little bit change

STEP 1
CONN SYS/ORACLE AS SYSDBA
GRANT EXECUTE ON DBMS_DDL TO SCOTT;

STEP 2
CONN SCOTT/TIGER

CREATE OR REPLACE PROCEDURE ANALYZE_OBJECTS IS
 CURSOR C1 IS SELECT TABLE_NAME, USER OWNER FROM USER_TABLES;
 CNTR NUMBER:=0;
BEGIN
 FOR I IN C1 LOOP
  DBMS_DDL.ANALYZE_OBJECT('TABLE',I.OWNER,I.TABLE_NAME,'COMPUTE');
 END LOOP;
 DBMS_OUTPUT.PUT_LINE('ALL TABLES ANALYZED..');
EXCEPTION
 WHEN OTHERS THEN
 &D(SQLCODE||CHR(10)||&ERRM);
END;

ALTER PROCEDURE ANALYZE_OBJECTS COMPILE;

STEP 3
VAR JOB_ID NUMBER;
EXECUTE DBMS_JOB.SUBMIT(:JOB_ID,'ANALYZE_OBJECTS;',SYSDATE, 'SYSDATE+1/1440');

ABOVE PROCEDURE REPEAT AFTER ONE MINUTE
SELECT TABLE_NAME, NUM_ROWS FROM USER_TABLES;


No comments:

Post a Comment