Begin FOR IN Select From Where IN: 'Table' 'VIEW' 'Package' 'Procedure' 'Function' 'Sequence'
Begin FOR IN Select From Where IN: 'Table' 'VIEW' 'Package' 'Procedure' 'Function' 'Sequence'
'SEQUENCE' )) LOOP BEGIN IF cur_rec.object_type = 'TABLE' THEN EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '" CASCADE CONSTRAINTS'; ELSE EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"'; END IF; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line ( 'FAILED: DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"' ); END; END LOOP; END; /
SET ECHO OFF SET FEEDBACK OFF SET HEADING OFF SET MARKUP HTML OFF SET ESCAPE \ SPOOL drop_tables.sql select 'drop table ', table_name, 'cascade constraints \;' from user_tables; / select 'drop sequence ',object_name,'\;' from user_objects where object_type='SEQUENCE'; / SPOOL OFF @drop_tables.sql SET ECHO ON SET FEEDBACK ON SET HEADING ON
set heading off; set feedback off; spool C:my_file_name.sql select 'delete from ' || tname ||';' from tab where tabtype = 'TABLE'; spool off;
set heading off; set feedback off; spool C:my_file_name.sql select 'drop table ' || table_name || 'cascade constraints;' from user_tables; spool off;
SELECT COUNT(*) "ACTIVE USERS" FROM v_$session WHERE username IS NOT NULL;
select lpad(' ', 2*level) || granted_role "User, his roles and privileges" from ( /* THE USERS */ select null grantee, username granted_role from dba_users where username like upper('%&enter_username%') /* THE ROLES TO ROLES RELATIONS */ union select grantee, granted_role from dba_role_privs /* THE ROLES TO PRIVILEGE RELATIONS */ union select grantee, privilege from dba_sys_privs ) start with grantee is null connect by grantee = prior granted_role;
For all tables ============== SELECT 'DROP TABLE ' || owner || '.' || table_name || ' CASCADE CONSTRAINTS;' FROM all_tables /
For all triggers ================ SELECT 'DROP TRIGGER ' || owner || '.' || trigger_name || ' ;' FROM all_triggers /
For all sequences ================= SELECT 'DROP SEQUENCE ' || sequence_owner || '.' || sequence_name || ' ;' FROM all_sequences / Custom for specific owners/users (but make sure you log in as SYSDBA) Also substitute the sql above if tables, triggers or sequences and include/exclude users/owners as needed ====================================================================
Example for sequence SELECT 'DROP SEQUENCE ' || sequence_owner || '.' || sequence_name || ';' FROM all_sequences where sequence_owner IN ( 'SCOTT', 'SH', 'SSS', 'TEST1', . . . . . 'WHD' )
-------Here is the SQL Script: Begin for c in (select table_name from user_tables) loop execute immediate ('drop table '||c.table_name||' cascade constraints); end loop; End; Take note!! 1. You need to log in to that user which you wanted to drop the tables 1. DECLARE 2. 3. 4. 5. 6. table_name VARCHAR2(30); CURSOR usertables IS SELECT * FROM user_tables WHERE table_name NOT LIKE 'BIN$%'; BEGIN FOR next_row IN usertables LOOP
7. 8. 9.
EXECUTE IMMEDIATE 'drop table ' || next_row.table_name || ' cascade constraints'; END LOOP; END;
save
drop.sql: ================================ set heading off set newpage none set serveroutput on size 100000 DECLARE CUR INTEGER; OBJNAME VARCHAR2(128); CURSOR C1 IS SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE='TABLE'; BEGIN OPEN C1; LOOP BEGIN FETCH C1 INTO OBJNAME; EXIT WHEN C1%NOTFOUND; CUR:=DBMS_SQL.OPEN_CURSOR; DBMS_OUTPUT.PUT_LINE('Dropping' || ' TABLE ' || OBJNAME); DBMS_SQL.PARSE(CUR, 'DROP TABLE ' || OBJNAME || ' CASCADE CONSTRAINTS' , DBMS_SQL.NATIVE); DBMS_SQL.CLOSE_CURSOR(CUR); EXCEPTION WHEN OTHERS THEN dbms_output.put_line('Exception encountered for ' || OBJNAME); END; END LOOP; CLOSE C1; COMMIT; EXCEPTION WHEN OTHERS THEN NULL; END; /