資源描述:
《oracle 9i取得建表和索引ddl語句》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、我們都知道在9i之前,要想獲得建表和索引的語句是一件很麻煩的事。我們通常的做法都是通過exportwithrows=no來得到,但它的輸出因為格式的問題并不能直接拿來用。而另一種方法就是寫復(fù)雜的腳本來查詢數(shù)據(jù)字典,但這對于一稍微復(fù)雜的對象,如IOT和嵌套表等,還是無法查到。從數(shù)據(jù)字典中獲得DDL語句是經(jīng)常要用的,特別是在系統(tǒng)升級/重建的時候。在Oracle9i中,我們可以直接通過執(zhí)行dbms_metadata從數(shù)據(jù)字典中查處DDL語句。使用這個功能強大的工具,我們可以獲得單個對象或整個SCHEMA的DDL語句。最好不過的是因為它使用起來很簡單。1、獲得單個表和索引DDL
2、語句的方法:setheadingoff; setechooff;Setpages999; setlong90000; spoolget_single.sql selectdbms_metadata.get_ddl("TABLE","SZT_PQSO2","SHQSYS")fromdual;selectdbms_metadata.get_ddl("INDEX","INDXX_PQZJYW","SHQSYS")fromdual;spooloff;下面是輸出。我們只要把建表/索引語句取出來在后面加個分號就可以直接運行了。SQL>selectdbms_metadata.get_
3、ddl("TABLE","SZT_PQSO2","SHQSYS")fromdual;CREATETABLE"SHQSYS"."SZT_PQSO2" ("PQBH"VARCHAR2(32)NOTNULLENABLE,"ZJYW"NUMBER(10,0),"CGSO"NUMBER(10,0)NOTNULLENABLE,"SOLS"VARCHAR2(17),"SORQ"VARCHAR2(8),"SOWR"VARCHAR2(8),"SOCL"locatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassina
4、tion.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcameVARCHAR2(6),"YWHM"VARCHAR2(10),"YWLX"VARCHAR2(6))PCTFREE10PCTUSED40INITRANS1MAXTRANS255NOCOMPRESSLOGGINGSTORAGE(INITIAL1048576NEXT1048576MINEXTENTS1MAXEXTENT
5、S2147483645PCTINCREASE0FREELISTS1FREELISTGROUPS1BUFFER_POOLDEFAULT)TABLESPACE"DATA1"SQL>selectdbms_metadata.get_ddl("INDEX","INDXX_PQZJYW","SHQSYS")fromdual;CREATEINDEX"SHQSYS"."INDXX_PQZJYW"ON"SHQSYS"."SZT_PQSO2"("ZJYW")PCTFREE10INITRANS2MAXTRANS255STORAGE(INITIAL1048576NEXT1048576MINEX
6、TENTS1MAXEXTENTS2147483645 PCTINCREASE0FREELISTS1FREELISTGROUPS1BUFFER_POOLDEFAULT) TABLESPACE"DATA1"SQL> SQL>spooloff;2、獲得整個SCHEMADDL語句的方法:setpagesize0setlong90000setfeedbacklocatedintheTomb,DongShenJiabang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemast
7、ers(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcameoffsetechooffspoolget_schema.sqlconnectshqsys/shqsys@hawk1;SELECTDBMS_METADATA.GET_DDL("TABLE",u.table_name)FROMUSER_TABLESu; SELECTDBMS_METADATA.GET_DDL("INDEX",u.index_name)FROMUSER_I