Question

I have one database called TEST.

in this database I have two different schemas, one called DEV (old) and second called RC (newly added).

before multipule schemas, there was no problem for dropping tables by using folloing script.

DECLARE
  CURSOR C1 IS SELECT OBJECT_NAME,OBJECT_TYPE FROM USER_OBJECTS WHERE OBJECT_TYPE!='INDEX' ORDER BY OBJECT_TYPE DESC;
  object_name VARCHAR2(50);
  object_type VARCHAR2(50);
  column_name VARCHAR2(50);
BEGIN
  OPEN C1;
  LOOP
    FETCH C1 INTO object_name,object_type;
    EXIT WHEN (C1%NOTFOUND);
    BEGIN
      IF object_type='TABLE' THEN
        EXECUTE IMMEDIATE 'DROP '||object_type||' '||object_name||' cascade constraints';
      ELSE
        EXECUTE IMMEDIATE 'DROP '||object_type||' '||object_name;
      END IF;
    END;
  END LOOP;
  CLOSE C1;
EXCEPTION
  WHEN OTHERS THEN
    NULL;
END;
EXIT

Now if i want to import a new dump for RC schema then how could i drop RC.tables by using this script. I am afraid if i would be using this script then it would drop all tables releated to DEV and RC.

Was it helpful?

Solution

If you connect to the database using the RC user credentials then your script will only drop the objects in the RC schema.

The script drops the objects in the schema you are logged in to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top