views:

689

answers:

1

Hi Experts,

I am using the below script for generating a DDL to create tablespaces in the database.

select 'create tablespace ' || df.tablespace_name || chr(10)
 || ' datafile ''' || df.file_name || ''' size ' || df.bytes 
 || decode(autoextensible,'N',null, chr(10) || ' autoextend on maxsize ' 
 || maxbytes) 
 || chr(10) 
 || 'default storage ( initial ' || initial_extent 
 || decode (next_extent, null, null, ' next ' || next_extent )
 || ' minextents ' || min_extents
 || ' maxextents ' ||  decode(max_extents,'2147483645','unlimited',max_extents) 
 || ') ;' "Script To Recreate Tablespaces"
 from dba_data_files df, dba_tablespaces t
 where df.tablespace_name=t.tablespace_name;

It works good. But when a tablespace contains two datafiles then also it creates seperate command with create tablespace. Simply it creates two create tablespace commands if a tablespace contains two datafiles. Please share your thoughts.

Cheers,

Srinivasan Thirunavukkarasu.

+1  A: 

If you're just trying to reverse-engineer an existing tablespace to generate a script, why not just use DBMS_METADATA?

select dbms_metadata.get_ddl('TABLESPACE','yourTablespaceNameOfInterest') 
from dual;

You can generate one of these statements for each tablespace in the database with a simple wrapper if you want them all.

dpbradley
Hi,I think DBMS_METADATA is available only in 10g. Mine is 9i database.Cheers,Srinivasan Thirunavukkarasu.
Srinivasan Thirunavukkarasu
I'm pretty sure a 9i installation includes DBMS_METADATA - perhaps you don't have permissions on the package?
dpbradley
Yes its there. Thanks man.
Srinivasan Thirunavukkarasu
Srinivasan, if you were asking about 9i, why did you put 10g in the question title ?
Gary