Last Updated: February 25, 2016
·
650
· kamilmichalak

Dropping all tables in database

Just for development purposes

-- Database clearing script 
-- This PL/SQL procedure drops all tables which names 
-- are present inUSER_TABLES 
set serveroutput on;
DECLARE
  CURSOR c_get_tables IS
    SELECT table_name from user_tables;
BEGIN
  FOR cursor_item IN c_get_tables
  LOOP
    EXECUTE IMMEDIATE 
      'DROP TABLE ' || cursor_item.table_name || ' CASCADE CONSTRAINTS';
    dbms_output.put_line('Dropped table: ' || cursor_item.table_name);
    -- There's no DML operations so transaction commit is not needed. 
  END LOOP;
END;