|
|
Truncate Tables in Schema
Script
Brian Peasland, DBA Pipeline SYSOP
This PL/SQL block can be used to go into a schema and truncate tables that have ANY rows.
DECLARE
vTableName DBA_TABLES.TABLE_NAME%TYPE;
truncTable VARCHAR2(2000);
CURSOR c1 IS select table_name FROM dba_tables
where username='myuser';
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO vTableName;
EXIT WHEN c1%NOTFOUND;
truncTable := 'truncate table ' || vTableName;
EXECUTE IMMEDIATE truncTable;
END LOOP;
CLOSE c1;
END;
/
</PRE>
Other than connect as DBA privilege to run the script, the owner of the table doesn't need any specific privileges to truncate their own tables. But if you want someone else to be able to truncate another user's table, then they'll need delete privileges on that table. I'd stay away from DELETE ANY if at all possible due to the massive amount of damage that could be done to sensitive, precious data in the entire database.