
正文
DBMS_METADATA中使用SESSION_TRANSFORM过滤不想获取的DDL
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
我们一般使用dbms_metadata.get_ddl获取对象的ddl的时候,有时会获取一些其它额外的信息,比如当你想获取表的创建语句的时候,你会得到表的约束信息,这个信息可能是你不想要的,那么就能够用SESSION_TRANSFORM对它进行过滤。
看以下的演示样例,创建一个有主键和外键的表,获取他的ddl语句:
SQL> CREATE TABLE tb1 (id int primary key);Table created.SQL> create table tb2 (id int primary key references tb1(id));Table created.
SQL> insert into tb1 values(1);1 row created.SQL> commit;Commit complete.SQL> insert into tb2 values(1);1 row created.SQL> commit;SQL> select dbms_metadata.get_ddl('TABLE','TB2','TEST') from dual;DBMS_METADATA.GET_DDL('TABLE','TB2','TEST')
-------------------------------------------------------------------------------- CREATE TABLE "TEST"."TB2"
("ID" NUMBER(*,0),
PRIMARY KEY ("ID")
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 FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE,
FOREIGN KEY ("ID")
REFERENCES "TEST"."TB1" ("ID") ENABLE
) SEGMENT CREATION IMMEDIATE
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 FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
不单单是获取到了创建的基本字段的语句。还有主键,约束。外键。存储參数。表空间等,假设这些你不须要,都是能够进行过滤的,比如我过滤掉主键、外键、存储信息
使用例如以下语句:
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',false);PL/SQL procedure successfully completed.exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',false);PL/SQL procedure successfully completed.SQL> exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);PL/SQL procedure successfully completed.SQL>
SQL> select dbms_metadata.get_ddl('TABLE','TB2','TEST') from dual;DBMS_METADATA.GET_DDL('TABLE','TB2','TEST')
-------------------------------------------------------------------------------- CREATE TABLE "TEST"."TB2"
("ID" NUMBER(*,0)
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
TABLESPACE "USERS"
还能够对其它的一些信息做过滤,表格例如以下:
Table 87-22 SET_TRANSFORM_PARAM: Transform Parameters for the DDLTransform
Object Type | Name | Datatype | Meaning |
All objects | PRETTY | BOOLEAN | If TRUE, format the output with indentation and line feeds. Defaults toTRUE. |
All objects | SQLTERMINATOR | BOOLEAN | If TRUE, append a SQL terminator (; or /) |
TABLE | SEGMENT_ATTRIBUTES | BOOLEAN | If TRUE, include segment attributes clauses in the DDL. If FALSE, omit them. |
TABLE | STORAGE | BOOLEAN | If TRUE, include storage clauses in the DDL. If FALSE, omit them. Defaults |
TABLE | TABLESPACE | BOOLEAN | If TRUE, include tablespace clauses in the DDL. If FALSE, omit them. (Ignored |
TABLE | CONSTRAINTS | BOOLEAN | If TRUE, include all non-referential table constraints in the DDL. If FALSE, |
TABLE | REF_CONSTRAINTS | BOOLEAN | If TRUE, include all referential constraints (foreign keys) in the DDL. IfFALSE, |
TABLE | CONSTRAINTS_AS_ALTER | BOOLEAN | If TRUE, include table constraints as separate ALTER TABLE (and, if necessary, CREATE |
TABLE | OID | BOOLEAN | If TRUE, include the OID clause for object tables in the DDL. If FALSE, omit |
TABLE | SIZE_BYTE_KEYWORD | BOOLEAN | If TRUE, include the BYTE keyword as part of the size specification ofCHAR and VARCHAR2 columns |
TABLE, INDEX | PARTITIONING | BOOLEAN | If TRUE, include partitioning clauses in the DDL. If FALSE, omit them. Defaults |
INDEX, CONSTRAINT,ROLLBACK_SEGMENT,CLUSTER, TABLESPACE | SEGMENT_ATTRIBUTES | BOOLEAN | If TRUE, include segment attributes clauses (physical attributes, storage attributes, tablespace, logging) in the DDL. If FALSE, |
INDEX, CONSTRAINT,ROLLBACK_SEGMENT, CLUSTER | STORAGE | BOOLEAN | If TRUE, include storage clauses in the DDL. If FALSE, omit them. (Ignored |
INDEX, CONSTRAINT,ROLLBACK_SEGMENT, CLUSTER | TABLESPACE | BOOLEAN | If TRUE, include tablespace clauses in the DDL. If FALSE, omit them. (Ignored |
TYPE | SPECIFICATION | BOOLEAN | If TRUE, include the type specification in the DDL. If FALSE, omit it. Defaults |
TYPE | BODY | BOOLEAN | If TRUE, include the type body in the DDL. If FALSE, omit it. Defaults toTRUE. |
TYPE | OID | BOOLEAN | If TRUE, include the OID clause in the DDL. If FALSE, omit it. Defaults toFALSE. |
PACKAGE | SPECIFICATION | BOOLEAN | If TRUE, include the package specification in the DDL. If FALSE, omit it. |
PACKAGE | BODY | BOOLEAN | If TRUE, include the package body in the DDL. If FALSE, omit it. Defaults |
VIEW | FORCE | BOOLEAN | If TRUE, use the FORCE keyword in the CREATE |
OUTLINE | INSERT | BOOLEAN | If TRUE, include the INSERT statements into the OL$ dictionary tables that Note: This object type is being deprecated. |
All objects | DEFAULT | BOOLEAN | Calling SET_TRANSFORM_PARAM with this parameter set to TRUE has the effect |
All objects | INHERIT | BOOLEAN | If TRUE, inherits session-level parameters. Defaults to FALSE. If an application |
ROLE | REVOKE_FROM | Text | The name of a user from whom the role must be revoked. If this is a non-null string and if the CREATE ROLE statement Note: When you issue a CREATE ROLE statement, Oracle may grant you the role. Defaults to null string. |
TABLESPACE | REUSE | BOOLEAN | If TRUE, include the REUSE parameter for datafiles in a tablespace to indicate Defaults to FALSE. |
CLUSTER, INDEX,ROLLBACK_SEGMENT, TABLE,TABLESPACE | PCTSPACE | NUMBER | A number representing the percentage by which space allocation for the object type is to be modified. The value is the number of one-hundreths of the current allocation. For example, 100 means 100%. If the object type is TABLESPACE, the following size values are affected: - in file specifications, the value of SIZE - MINIMUM EXTENT - EXTENT MANAGEMENT LOCAL UNIFORM SIZE For other object types, INITIAL and NEXT are affected. |







