日期:2014-05-16  浏览次数:20432 次

删除数据库一个用户下的所有对象.
DECLARE

    Drop_Cmd VARCHAR(200);
    CURSOR Cur_Objects IS
        SELECT 'drop table ' || Table_Name || ' CASCADE CONSTRAINTS '
        FROM User_Tables
        UNION ALL

        SELECT 'drop view ' || View_Name || ' CASCADE CONSTRAINTS '
        FROM User_Views
        UNION ALL

        SELECT 'DROP FUNCTION ' || Object_Name
        FROM User_Objects o
        WHERE o.Object_Type = 'FUNCTION'

        UNION ALL
        SELECT 'drop SEQUENCE ' || SEQUENCE_Name || ' '
        FROM User_Sequences;
BEGIN

    --disable all
    OPEN Cur_Objects;
    LOOP
        FETCH Cur_Objects
            INTO Drop_Cmd;
        EXIT WHEN Cur_Objects%NOTFOUND;

        EXECUTE IMMEDIATE Drop_Cmd;
    END LOOP;

    CLOSE Cur_Objects;

END;