资源描述:
《oracle 9i取得建表和索引ddl语句》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、我们都知道在9i之前,要想获得建表和索引的语句是一件很麻烦的事。我们通常的做法都是通过exportwithrows=no来得到,但它的输出因为格式的问题并不能直接拿来用。而另一种方法就是写复杂的脚本来查询数据字典,但这对于一稍微复杂的对象,如IOT和嵌套表等,还是无法查到。从数据字典中获得DDL语句是经常要用的,特别是在系统升级/重建的时候。在Oracle9i中,我们可以直接通过执行dbms_metadata从数据字典中查处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