It's not who you are underneath, it's what you do that defines you

清空oracle数据库

在开发过程中,可能经常需要重新初始化数据库,在初始化之前,我们肯定希望不再有以前的老表、存储过程等用户对象,用下面的教本就可以做到这一点: 

BEGIN 
    FOR rec IN 
    (SELECT object_name,object_type from user_objects 
    WHERE object_type='PROCEDURE' 
    OR object_type='TABLE' 
    OR object_type='VIEW' 
    OR object_type='FUNCTION' 
    OR object_type='PACKAGE' 
    OR object_type='SEQUENCE' 
    ) 
    LOOP 
        IF rec.object_type='TABLE' THEN 
           EXECUTE IMMEDIATE 'DROP '||rec.object_type||' '||rec.object_NAME||' CASCADE CONSTRAINTS'; 
        ELSE 
            EXECUTE IMMEDIATE 'DROP '||rec.object_type||' '||rec.object_NAME; 
        END IF; 
   END LOOP;     
END; 
/ 
    --  不过对于改用户的job,用上面的方法则不行,可以通过下面的方法来删除: 
FOR x IN (SELECT * FROM user_jobs) 
LOOP 
     dbms_job.remove (x.job); 
END LOOP;

 

posted @ 2016-12-09 15:41  金铭杰  阅读(1464)  评论(0编辑  收藏  举报

Brick walls are there for a reason :they let us prove how badly we want things