Advertisement
andrewb

pidm_quest.sql

Jul 6th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.39 KB | None | 0 0
  1. DECLARE
  2.   spid  VARCHAR2(10) := '&pidm';
  3.   spcnt NUMBER;
  4.   tbcnt NUMBER := 0;
  5.   tnam  VARCHAR2(100);
  6.   cnam  VARCHAR2(100);
  7.   newqry  VARCHAR2(255);
  8.   sprow SPRIDEN%ROWTYPE;
  9.  
  10.   CURSOR get_p_tbls IS
  11.     SELECT a.TABLE_NAME, b.COLUMN_NAME
  12.       FROM ALL_TAB_COMMENTS a, ALL_TAB_COLUMNS b
  13.       WHERE a.TABLE_NAME = b.TABLE_NAME  AND UPPER(b.COLUMN_NAME) LIKE UPPER('%pidm%')
  14.       AND a.TABLE_TYPE = 'TABLE' AND a.OWNER IN ('SATURN', 'FAISMGR') ORDER BY a.TABLE_NAME;  
  15. BEGIN
  16.   DBMS_OUTPUT.ENABLE;
  17.  
  18.   EXECUTE IMMEDIATE 'SELECT * FROM SPRIDEN WHERE SPRIDEN_PIDM = '''||spid||''' and SPRIDEN_CHANGE_IND IS NULL' INTO sprow;
  19.  
  20.   DBMS_OUTPUT.PUT_LINE(sprow.spriden_last_name||', '||sprow.spriden_first_name||' ('||sprow.spriden_id||')');
  21.   DBMS_OUTPUT.PUT_LINE('---');
  22.  
  23.   OPEN get_p_tbls;
  24.   LOOP
  25.     FETCH get_p_tbls INTO tnam, cnam;
  26.     EXIT WHEN get_p_tbls%NOTFOUND;
  27.    
  28.     EXECUTE IMMEDIATE 'SELECT COUNT('||cnam||') FROM '||tnam||' WHERE '||cnam||' = '''||spid||'''' INTO spcnt;
  29.    
  30.     IF spcnt > 0 THEN
  31.       DBMS_OUTPUT.PUT_LINE(tnam||': '||cnam||' ('||spcnt||')');
  32.       tbcnt := tbcnt + 1;
  33.     END IF;
  34.  
  35.   END LOOP;
  36.   CLOSE get_p_tbls;
  37.  
  38.   DBMS_OUTPUT.PUT_LINE('---');
  39.   DBMS_OUTPUT.PUT_LINE('PIDM is in '||tbcnt||' table(s).');
  40. EXCEPTION
  41.   WHEN OTHERS THEN
  42.     DBMS_OUTPUT.PUT_LINE('Exception: SQLCODE=' || SQLCODE || '  SQLERRM=' || SQLERRM);
  43.     RAISE;
  44. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement