我想从模式中删除对象,并且我已将所有不应删除的对象存储在表中,所有其他不在表中的对象都应删除。我有以下不起作用的代码可以在这里帮助我。我在网上搜索过只有一件事“删除所有对象”与我的情况无关。
DECLARE
stringa VARCHAR2(100);
stringb VARCHAR2(1000) := '';
CURSOR cur IS
SELECT *
FROM user_objects;
BEGIN
FOR c IN cur LOOP
BEGIN
stringa := '';
BEGIN
SELECT tab_name
INTO stringb
FROM zretain_list;
IF c.object_type = 'VIEW' THEN
stringa := 'drop view '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'TABLE'
AND c.object_name != stringb THEN
stringa := 'drop table "'
|| c.object_name
|| '" cascade constraints';
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'SEQUENCE' THEN
stringa := 'drop sequence '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'PACKAGE' THEN
stringa := 'drop package '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'TRIGGER' THEN
stringa := 'drop trigger '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'PROCEDURE' THEN
stringa := 'drop procedure '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'FUNCTION' THEN
stringa := 'drop function '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'SYNONYM' THEN
stringa := 'drop synonym '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'INDEX' THEN
stringa := 'drop index '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'PACKAGE BODY' THEN
stringa := 'drop PACKAGE BODY '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
ELSIF c.object_type = 'DATABASE LINK' THEN
stringa := 'drop database link '
|| c.object_name;
EXECUTE IMMEDIATE stringa;
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
-- PURGE recyclebin
END;
END;
END LOOP;
END;
/