删除用户所有的表,带有级联关系:
--创建存储过程
CREATE OR REPLACE
PROCEDURE DROPTABLES IS
V_SQL VARCHAR2(2000);
CURSOR CUR IS SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME;
BEGIN
FOR ROWS IN CUR LOOP V_SQL := 'drop TABLE ' || ROWS.TABLE_NAME || ' cascade constraints';
DBMS_OUTPUT.PUT_LINE(V_SQL);
EXECUTE IMMEDIATE V_SQL;
END LOOP;
EXECUTE IMMEDIATE 'purge recyclebin';
END DROPTABLES;
--执行存储过程
begin
-- Call the procedure
droptables;
end;
建议在执行该存储过程之前先对数据库进行备份。