Pages

Monday, 15 December 2014

Oracle - Clean the objects inside the schema for refresh using Import(Impdp).

Below script will help to clean the objects in the schema,We you are refreshing using export and import method. 

Login to the schema and run the script.

 set serveroutput on;

 DECLARE
 l_count NUMBER;
 l_cascade VARCHAR2(20);
 BEGIN
 << dependency_failure_loop >>
 FOR i IN 1 .. 5 LOOP
 EXIT dependency_failure_loop WHEN l_count = 0;
 l_count := 0;

 FOR cur_rec IN (SELECT object_name, object_type
 FROM user_objects) LOOP
 BEGIN
 l_count := l_count + 1;
 l_cascade := NULL;
 IF cur_rec.object_type = 'TABLE' THEN
 l_cascade := ' CASCADE CONSTRAINTS';
 END IF;
 EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"' || l_cascade;
 EXCEPTION
 WHEN OTHERS THEN
 NULL;
 END;
 END LOOP;
 EXECUTE IMMEDIATE 'PURGE RECYCLEBIN';
 DBMS_OUTPUT.put_line('Pass: ' || i || ' Drops: ' || l_count);
 END LOOP;
 END;
 /

No comments:

Post a Comment