1

スキーマからオブジェクトを削除したいのですが、削除してはならないすべてのオブジェクトをテーブルに保存しました。テーブルにない他のすべてのオブジェクトを削除する必要があります。私は動作していない次のコードを持っています誰かがここで私を助けることができます。私はネットを検索しましたが、私の場合とは関係のない「すべてのオブジェクトを削除」が1つだけあります。

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;

/ 
4

1 に答える 1

2

あなたは次のようなものから始めることができます

begin
  For i in (select object_type, object_name from user_objects o
            where object_name != 'ZRETAIN_LIST' and object_type in ('TABLE', 'FUNCTION', 'PROCEDURE', 'PACKAGE', 'SEQUENCE' )
            and not exists ( select 1 from zretain_list where tab_name = o.object_name ) )
  loop
    execute immediate 'drop '||i.object_type || ' ' || i.object_name ;
  end loop;
end;
/
于 2012-12-29T13:00:47.740 に答える