ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 여러 스키마들의 유저 정보 및 DB Link를 제외한 모든 정보 삭제
    DB/Oracle 2024. 11. 4. 16:51
    반응형
    BEGIN
       -- 스키마 목록
       FOR schema_name IN (
          SELECT 'Schema1' AS schema_name FROM dual UNION ALL
          SELECT 'Schema2' FROM dual UNION ALL
          SELECT 'Schema3' FROM dual UNION ALL
          SELECT 'Schema4' FROM dual UNION ALL
          SELECT 'Schema5' FROM dual UNION ALL
          SELECT 'Schema6' FROM dual UNION ALL
          SELECT 'Schema7' FROM dual
       ) LOOP
    
          -- 1. 테이블 삭제 (CASCADE CONSTRAINTS 포함)
          FOR t IN (SELECT table_name FROM all_tables WHERE owner = schema_name.schema_name) LOOP
             EXECUTE IMMEDIATE 'DROP TABLE ' || schema_name.schema_name || '.' || t.table_name || ' CASCADE CONSTRAINTS';
          END LOOP;
    
          -- 2. 독립적으로 생성된 인덱스 삭제
          FOR idx IN (SELECT index_name FROM all_indexes WHERE owner = schema_name.schema_name AND table_name IS NULL) LOOP
             EXECUTE IMMEDIATE 'DROP INDEX ' || schema_name.schema_name || '.' || idx.index_name;
          END LOOP;
    
          -- 3. 프로시저, 함수, 패키지 삭제
          FOR obj IN (
             SELECT object_name, object_type 
             FROM all_objects 
             WHERE owner = schema_name.schema_name 
             AND object_type IN ('PROCEDURE', 'FUNCTION', 'PACKAGE')
          ) LOOP
             EXECUTE IMMEDIATE 'DROP ' || obj.object_type || ' ' || schema_name.schema_name || '.' || obj.object_name;
          END LOOP;
    
          -- 4. 잡(JOB) 삭제
          FOR job IN (SELECT job_name FROM all_scheduler_jobs WHERE owner = schema_name.schema_name) LOOP
             DBMS_SCHEDULER.drop_job(job_name => schema_name.schema_name || '.' || job.job_name, force => TRUE);
          END LOOP;
    
       END LOOP;
    END;
    /
    반응형

    'DB > Oracle' 카테고리의 다른 글

    Oracle DB - expdp / impdp  (0) 2024.08.27
    DB User별 - Session Timeout 설정  (0) 2024.07.17
    RDS - SESSION KILL  (0) 2024.06.11
    Table Space 공간 확인  (0) 2024.01.25
    Table 별 데이터 사용량 체크  (0) 2024.01.25

    댓글

Designed by Tistory.