DECLARE var_mod number; CURSOR c1 IS SELECT tablespace_name, ROUND(SUM(bytes)/(1024*1024),0) AS mb FROM dba_data_files WHERE tablespace_name IN (SELECT DISTINCT tablespace_name FROM dba_segments WHERE owner IN ('<schema_name>','<schema_name>','<schema_name>','<schema_name>')) GROUP BY tablespace_name ORDER BY 1; BEGIN FOR tblspc IN c1 LOOP var_mod := FLOOR(tblspc.mb/9216); IF tblspc.mb <= 9216 THEN DBMS_OUTPUT.PUT_LINE ('CREATE TABLESPACE '||tblspc.tablespace_name||' DATAFILE SIZE '||tblspc.mb||'M AUTOEXTEND ON MAXSIZE 9G;'); ELSIF REMAINDER(tblspc.mb, 9216) = 0 THEN DBMS_OUTPUT.PUT_LINE ('CREATE TABLESPACE '||tblspc.tablespace_name||' DATAFILE SIZE 9G AUTOEXTEND ON MAXSIZE 9G;'); FOR i IN 1..var_mod LOOP var_mod := var_mod - 1; DBMS_OUTPUT.PUT_LINE ('ALTER TABLESPACE '||tblspc.tablespace_name||' ADD DATAFILE SIZE 9G AUTOEXTEND ON MAXSIZE 9G;'); END LOOP; ELSE DBMS_OUTPUT.PUT_LINE ('CREATE TABLESPACE '||tblspc.tablespace_name||' DATAFILE SIZE 9G AUTOEXTEND ON MAXSIZE 9G;'); FOR i IN 1..var_mod LOOP var_mod := var_mod - 1; DBMS_OUTPUT.PUT_LINE ('ALTER TABLESPACE '||tblspc.tablespace_name||' ADD DATAFILE SIZE 9G AUTOEXTEND ON MAXSIZE 9G;'); END LOOP; END IF; var_mod :=0; END LOOP; END; /
This piece of code will gather all used tablespaces by given schema's and output create statements for those tablespaces broken down into separate files of max. 9G.
Use at your own leisure and discretion... As always: No support and no responsibility