dbms_metadata.get_ddl學習
今天在網上看到介紹dbms_metadata.get_ddl的文章,很不錯,學習下
1.顯示設定:
/*建立DBMS_METADATA:
@?/rdbms/admin/catmeta.sql
*/
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
set long 999999
SET PAGESIZE 1000
/*若希望不顯示storage引數:
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
*/
@?/rdbms/admin/catmeta.sql
*/
SET SERVEROUTPUT ON
SET LINESIZE 1000
SET FEEDBACK OFF
set long 999999
SET PAGESIZE 1000
/*若希望不顯示storage引數:
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
*/
2.9i R2所支援的45個OBJECT TYPE:
Type Name Meaning
------------------------------ ------------------------------
AUDIT_OBJ audits of schema objects
AUDIT audits of SQL statements
ASSOCIATION associate statistics
CLUSTER clusters
COMMENT comments
CONSTRAINT constraints
CONTEXT application contexts
DB_LINK database links
DEFAULT_ROLE default roles
DIMENSION dimensions
DIRECTORY directories
FUNCTION stored functions
INDEX indexes
INDEXTYPE indextypes
JAVA_SOURCE Java sources
LIBRARY external procedure libraries
MATERIALIZED_VIEW materialized views
MATERIALIZED_VIEW_LOG materialized view logs
OBJECT_GRANT object grants
OPERATOR operators
OUTLINE stored outlines
PACKAGE stored packages
PACKAGE_SPEC package specifications
PACKAGE_BODY package bodies
PROCEDURE stored procedures
PROFILE profiles
PROXY proxy authentications
REF_CONSTRAINT referential constraint
ROLE roles
ROLE_GRANT role grants
ROLLBACK_SEGMENT rollback segments
SEQUENCE sequences
SYNONYM synonyms
SYSTEM_GRANT system privilege grants
TABLE tables
TABLESPACE tablespaces
TABLESPACE_QUOTA tablespace quotas
TRIGGER triggers
TRUSTED_DB_LINK trusted links
TYPE user-defined types
TYPE_SPEC type specifications
TYPE_BODY type bodies
USER users
VIEW views
XMLSCHEMA XML schema
------------------------------ ------------------------------
AUDIT_OBJ audits of schema objects
AUDIT audits of SQL statements
ASSOCIATION associate statistics
CLUSTER clusters
COMMENT comments
CONSTRAINT constraints
CONTEXT application contexts
DB_LINK database links
DEFAULT_ROLE default roles
DIMENSION dimensions
DIRECTORY directories
FUNCTION stored functions
INDEX indexes
INDEXTYPE indextypes
JAVA_SOURCE Java sources
LIBRARY external procedure libraries
MATERIALIZED_VIEW materialized views
MATERIALIZED_VIEW_LOG materialized view logs
OBJECT_GRANT object grants
OPERATOR operators
OUTLINE stored outlines
PACKAGE stored packages
PACKAGE_SPEC package specifications
PACKAGE_BODY package bodies
PROCEDURE stored procedures
PROFILE profiles
PROXY proxy authentications
REF_CONSTRAINT referential constraint
ROLE roles
ROLE_GRANT role grants
ROLLBACK_SEGMENT rollback segments
SEQUENCE sequences
SYNONYM synonyms
SYSTEM_GRANT system privilege grants
TABLE tables
TABLESPACE tablespaces
TABLESPACE_QUOTA tablespace quotas
TRIGGER triggers
TRUSTED_DB_LINK trusted links
TYPE user-defined types
TYPE_SPEC type specifications
TYPE_BODY type bodies
USER users
VIEW views
XMLSCHEMA XML schema
3.舉例:
--表:(注意:表名要大寫)
SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','T2') FROM DUAL;
DBMS_METADATA.GET_DDL('TABLE','T2')
--------------------------------------------------------------------------------
CREATE TABLE "TEST"."T2"
( "OWNER" VARCHAR2(30),
"OBJECT_NAME" VARCHAR2(128),
"SUBOBJECT_NAME" VARCHAR2(30),
"OBJECT_ID" NUMBER,
"DATA_OBJECT_ID" NUMBER,
"OBJECT_TYPE" VARCHAR2(18),
"CREATED" DATE,
"LAST_DDL_TIME" DATE,
"TIMESTAMP" VARCHAR2(19),
"STATUS" VARCHAR2(7),
"TEMPORARY" VARCHAR2(1),
"GENERATED" VARCHAR2(1),
"SECONDARY" VARCHAR2(1)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE"
--索引:
SQL> SELECT DBMS_METADATA.GET_DDL('INDEX','IDX_OBJECT_NAME') FROM DUAL;
DBMS_METADATA.GET_DDL('INDEX','IDX_OBJECT_NAME')
--------------------------------------------------------------------------------
CREATE INDEX "TEST"."IDX_OBJECT_NAME" ON "TEST"."T2" ("OBJECT_NAME")
PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE"
--主鍵:
SQL> SELECT DBMS_METADATA.GET_DDL('CONSTRAINT','PK_AA') FROM DUAL;
DBMS_METADATA.GET_DDL('CONSTRAINT','PK_AA')
--------------------------------------------------------------------------------
ALTER TABLE "TEST"."PARENT" ADD CONSTRAINT "PK_AA" PRIMARY KEY ("BB")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE" ENABLE
--外來鍵:
SQL> SELECT DBMS_METADATA.GET_DDL('REF_CONSTRAINT','FK_AA') FROM DUAL;
DBMS_METADATA.GET_DDL('REF_CONSTRAINT','FK_AA')
--------------------------------------------------------------------------------
ALTER TABLE "TEST"."CHILD" ADD CONSTRAINT "FK_AA" FOREIGN KEY ("AA")
REFERENCES "TEST"."PARENT" ("BB") ENABLE
--表空間:
SQL> SELECT DBMS_METADATA.GET_DDL('TABLESPACE','SYSAUX') FROM DUAL;
SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','T2') FROM DUAL;
DBMS_METADATA.GET_DDL('TABLE','T2')
--------------------------------------------------------------------------------
CREATE TABLE "TEST"."T2"
( "OWNER" VARCHAR2(30),
"OBJECT_NAME" VARCHAR2(128),
"SUBOBJECT_NAME" VARCHAR2(30),
"OBJECT_ID" NUMBER,
"DATA_OBJECT_ID" NUMBER,
"OBJECT_TYPE" VARCHAR2(18),
"CREATED" DATE,
"LAST_DDL_TIME" DATE,
"TIMESTAMP" VARCHAR2(19),
"STATUS" VARCHAR2(7),
"TEMPORARY" VARCHAR2(1),
"GENERATED" VARCHAR2(1),
"SECONDARY" VARCHAR2(1)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE"
--索引:
SQL> SELECT DBMS_METADATA.GET_DDL('INDEX','IDX_OBJECT_NAME') FROM DUAL;
DBMS_METADATA.GET_DDL('INDEX','IDX_OBJECT_NAME')
--------------------------------------------------------------------------------
CREATE INDEX "TEST"."IDX_OBJECT_NAME" ON "TEST"."T2" ("OBJECT_NAME")
PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE"
--主鍵:
SQL> SELECT DBMS_METADATA.GET_DDL('CONSTRAINT','PK_AA') FROM DUAL;
DBMS_METADATA.GET_DDL('CONSTRAINT','PK_AA')
--------------------------------------------------------------------------------
ALTER TABLE "TEST"."PARENT" ADD CONSTRAINT "PK_AA" PRIMARY KEY ("BB")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "EXAMPLE" ENABLE
--外來鍵:
SQL> SELECT DBMS_METADATA.GET_DDL('REF_CONSTRAINT','FK_AA') FROM DUAL;
DBMS_METADATA.GET_DDL('REF_CONSTRAINT','FK_AA')
--------------------------------------------------------------------------------
ALTER TABLE "TEST"."CHILD" ADD CONSTRAINT "FK_AA" FOREIGN KEY ("AA")
REFERENCES "TEST"."PARENT" ("BB") ENABLE
--表空間:
SQL> SELECT DBMS_METADATA.GET_DDL('TABLESPACE','SYSAUX') FROM DUAL;
DBMS_METADATA.GET_DDL('TABLESPACE','SYSAUX')
------------------------------------------------------------------------
------------------------------------------------------------------------
CREATE TABLESPACE "SYSAUX" DATAFILE
'/u01/oracle/oradata/orcl/sysaux01.dbf
--使用者:
DBMS_METADATA.GET_DDL('USER','SYSTEM')
-------------------------------------------------------------------------------
ALTER USER "SYSTEM" IDENTIFIED BY VALUES 'S:C27C11320D7002613C610B3F5C293AE8
4.綜上所述:select dbms_metadata.get_ddl(’OBJECT_TYPE’,'OBJECT_NAME’,'SCHEMA’) from dual|user_xxx|all_xxx|dba_xxx;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8183550/viewspace-667778/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20230510]19c dg無法使用dbms_metadata.get_ddl檢視錶結構定義.txt
- 深度學習——學習目錄——學習中……深度學習
- 學習ThinkPHP,學習OneThinkPHP
- 深度學習學習框架深度學習框架
- 強化學習-學習筆記3 | 策略學習強化學習筆記
- 機器學習-整合學習機器學習
- 前端學習之Bootstrap學習前端boot
- 如何學習機器學習機器學習
- 強化學習-學習筆記2 | 價值學習強化學習筆記
- 機器學習——監督學習&無監督學習機器學習
- 深度學習+深度強化學習+遷移學習【研修】深度學習強化學習遷移學習
- 機器學習整合學習—Apple的學習筆記機器學習APP筆記
- 前端週刊第62期:學習學習再學習前端
- 學習產品快報09 | “CSDN學習”:增加學習提醒,提示學習不忘記
- 機器學習-整合學習LightGBM機器學習
- 機器學習:監督學習機器學習
- 程式設計學習MarkDown學習程式設計
- Golang 學習——interface 介面學習(一)Golang
- Golang 學習——interface 介面學習(二)Golang
- 強化學習10——迭代學習強化學習
- 機器學習之學習速率機器學習
- 深度學習學習7步驟深度學習
- 機器學習學習筆記機器學習筆記
- 免殺學習-基礎學習
- Go學習【二】學習資料Go
- 《JAVA學習指南》學習筆記Java筆記
- 機器學習&深度學習之路機器學習深度學習
- java學習之道 --- 如何學習java?Java
- 學習筆記【深度學習2】:AI、機器學習、表示學習、深度學習,第一次大衰退筆記深度學習AI機器學習
- 機器學習學習中,數學最重要!機器學習
- 【區塊鏈學習】《區塊鏈學習指南》學習筆記區塊鏈筆記
- 機器學習/深度學習書單推薦及學習方法機器學習深度學習
- 機器學習中的元學習機器學習
- 深度學習框架Pytorch學習筆記深度學習框架PyTorch筆記
- 機器學習&深度學習 操作tips機器學習深度學習
- 機器學習是深度學習之母機器學習深度學習
- 機器學習之學習曲線機器學習
- Flutter學習記錄(一)Dart學習FlutterDart
- 整合學習(一):簡述整合學習