Thursday, April 30, 2009

How to get DDL both as SQL statements and as XML data

We know with usage of sqlfile=file_name.txt all DDL statements inside dump file is populated inside file_name.txt file. The details of this is discussed on http://arjudba.blogspot.com/2008/04/extract-ddl-from-dump.html.

In many cases however you may want to extract metadata as XML format. With usage of both SQLFILE and TRACE you can achieve your goal.

C:>impdp full=y userid=arju/a dumpfile=arju_30_04.dmp logfile=arju_30_04.log SQLFILE=metadata_with_xml.sql TRACE=2

Import: Release 10.2.0.1.0 - Production on Friday, 01 May, 2009 9:30:56

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Master table "ARJU"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "ARJU"."SYS_SQL_FILE_FULL_01": full=y userid=arju/******** dumpfile=arju_30_04.dmp logfile=arju_30_04.log SQLF
ILE=metadata_with_xml.sql TRACE=2
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "ARJU"."SYS_SQL_FILE_FULL_01" successfully completed at 09:31:08

A sample output from the logfile is,
-- CONNECT ARJU
-- new object type path is: SCHEMA_EXPORT/USER
<?xml version="1.0"?><ROWSET><ROW>
<USER_T><VERS_MAJOR>1</VERS_MAJOR><VERS_MINOR>0</VERS_MINOR><USER_ID>61</USER_ID><NAME>ARJU</NAME><TYPE_NUM>1</TYPE_NUM><PASSWORD>55E19EAC6BA480EA</PASSWORD><DATATS>USERS</DATATS><TEMPTS>TEMP</TEMPTS><CTIME>16-APR-09</CTIME><PTIME>16-APR-09</PTIME><PROFNUM>0</PROFNUM><PROFNAME>DEFAULT</PROFNAME><DEFROLE>1</DEFROLE><ASTATUS>0</ASTATUS><LCOUNT>0</LCOUNT><DEFSCHCLASS>DEFAULT_CONSUMER_GROUP</DEFSCHCLASS><SPARE1>0</SPARE1></USER_T>
</ROW></ROWSET>
-- CONNECT SYSTEM
CREATE USER "ARJU" IDENTIFIED BY VALUES '55E19EAC6BA480EA'
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP";

-- new object type path is: SCHEMA_EXPORT/SYSTEM_GRANT
<?xml version="1.0"?><ROWSET><ROW>
<SYSGRANT_T><VERS_MAJOR>1</VERS_MAJOR><VERS_MINOR>1</VERS_MINOR><PRIVILEGE>-15</PRIVILEGE><GRANTEE>ARJU</GRANTEE><PRIVNAME>UNLIMITED TABLESPACE</PRIVNAME><SEQUENCE>918</SEQUENCE><WGO>0</WGO></SYSGRANT_T>
</ROW></ROWSET>
GRANT UNLIMITED TABLESPACE TO "ARJU";

-- new object type path is: SCHEMA_EXPORT/ROLE_GRANT
<?xml version="1.0"?><ROWSET><ROW>
<ROGRANT_T><VERS_MAJOR>1</VERS_MAJOR><VERS_MINOR>0</VERS_MINOR><GRANTEE_ID>61</GRANTEE_ID><GRANTEE>ARJU</GRANTEE><ROLE>DBA</ROLE><ROLE_ID>4</ROLE_ID><ADMIN>0</ADMIN><SEQUENCE>919</SEQUENCE></ROGRANT_T>
</ROW></ROWSET>
GRANT "DBA" TO "ARJU";

-- new object type path is: SCHEMA_EXPORT/DEFAULT_ROLE
<?xml version="1.0"?><ROWSET><ROW>
<DEFROLE_T><VERS_MAJOR>1</VERS_MAJOR><VERS_MINOR>0</VERS_MINOR><USER_ID>61</USER_ID><USER_NAME>ARJU</USER_NAME><USER_TYPE>1</USER_TYPE><DEFROLE>1</DEFROLE><ROLE_LIST/></DEFROLE_T>
</ROW></ROWSET>
ALTER USER "ARJU" DEFAULT ROLE ALL;

-- new object type path is: SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
<?xml version="1.0"?><ROWSET><ROW>
<PROCACTSCHEMA_T><VERS_MAJOR>1</VERS_MAJOR><VERS_MINOR>0</VERS_MINOR><USER_NAME>ARJU</USER_NAME><PACKAGE>DBMS_LOGREP_EXP</PACKAGE><SCHEMA>SYS</SCHEMA><LEVEL_NUM>5000</LEVEL_NUM><CLASS>2</CLASS><PREPOST>0</PREPOST><PLSQL><PLSQL_ITEM><LOCS><LOCS_ITEM><NEWBLOCK>0</NEWBLOCK><LINE_OF_CODE>sys.dbms_logrep_imp.instantiate_schema(schema_name=>SYS_CONTEXT('USERENV','CURRENT_SCHEMA'), export_db_name=>'ORCL.REGRESS.RDBMS.DEV.US.ORACLE.COM', inst_scn=>'1531485');</LINE_OF_CODE></LOCS_ITEM></LOCS></PLSQL_ITEM></PLSQL></PROCACTSCHEMA_T>
</ROW></ROWSET>

Related Documents

No comments:

Post a Comment