清空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;