SQL: delete all the data from all available tables

前端 未结 9 1142
小蘑菇
小蘑菇 2020-12-09 08:43

I am using oracle DB to maintain more than 30 tables, how can I delete all the data from all the tables? I only want to delete the data but not drop the tables.

9条回答
  •  时光取名叫无心
    2020-12-09 09:04

    Delete all the data from all tables in oracle

    DECLARE
      str VARCHAR2(100);
    BEGIN
      FOR i IN
      (SELECT object_name FROM user_objects WHERE object_type='TABLE'
      )
      LOOP
        str := 'Truncate table '|| i.object_name;
        EXECUTE IMMEDIATE str;
        DBMS_OUTPUT.PUT_LINE('table data deleted :' || i.object_name);
      END LOOP;
    END;

    For more info: http://www.oracleinformation.com/2014/10/delete-all-the-data-from-all-tables.html

提交回复
热议问题