Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:22:56+00:00 2026-06-16T17:22:56+00:00

I want to delete objects from schema and I have stored all the objects

  • 0

I want to delete objects from schema and I have stored all the objects those should not be deleted in a table, all other objects which are not in the table should be deleted. I have following code which is not working can some one help me here. I have searched the net there is only one thing “DELETE ALL OBJECT” which is not relevant to my case.

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;

/ 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:22:58+00:00Added an answer on June 16, 2026 at 5:22 pm

    You can start with something like

    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;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare objects from db4o and JSON.I should delete the object in
I want to delete DataRows from a DataTable. The rows to be deleted are
i want to remove some objects from a NSMutableDictionary after some Time. I have:
I want to have a collection of objects, which will be of a class
I want to delete/remove an object from an array list of objects. Would this
I have a list of JSON objects (received from a nosql db) and want
I have a table which is referenced by foreign keys on many other tables.
I've got a list of objects that I want to delete from the database.
I have two tables without any cascade deleting. I want to delete parent object
I want to delete all files in a directory with a given name, except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.