簡體   English   中英

在Oracle 10g中創建表空間腳本

[英]Create Tablespace Script in Oracle 10g

我使用以下腳本生成DDL以在數據庫中創建表空間。

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;

它運作良好。 但是當表空間包含兩個數據文件時,它還會使用create tablespace創建單獨的命令。 如果表空間包含兩個數據文件,它只創建兩個create tablespace命令。 請分享你的想法。

干杯,

Srinivasan Thirunavukkarasu。

如果您只是嘗試對現有表空間進行反向工程以生成腳本,為什么不使用DBMS_METADATA呢?

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

如果需要,可以使用簡單的包裝器為數據庫中的每個表空間生成其中一個語句。

SET LONG 1000000

select dbms_metadata.get_ddl('TABLESPACE','tablespace_name')||';' from dual;
select 
     dbms_metadata.get_ddl('TABLESPACE',tablespace_name) 
from
     dba_tablespaces
;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM