views:

1332

answers:

1

One can use the Oracle data pump import tool (IMPDP.EXE) to import one schema into another using the REMAP_SCHEMA option. However there is an issue in that triggers are not properly remapped. This leads to the trigger not being created at all with an error as follows:

ORA-39083: Object type TRIGGER failed to create with error: ORA-00942: table or view does not exist Failing sql is: CREATE TRIGGER "NEW_SCHEMA"."METER_ALARMS_BI"
BEFORE INSERT ON OLD_SCHEMA.METER_ALARMS ...

The reason for this is because the create SQL still refers to OLD_SCHEMA. It does say in the Oracle documentation that:

The mapping may not be 100 percent complete, because there are certain schema references that Import is not capable of finding. For example, Import will not find schema references embedded within the body of definitions of types, views, procedures, and packages.

IMHO this is a bit of a cop out by Oracle but that's another discussion!

According to Oracle Metalink note 750783.1, the workaround is to:

  1. Create a SQLFILE to include the relevant DDL command(s): impdp system/** directory=test_dp DUMPFILE=export_schemas.dmp remap_schema=u1:u2 sqlfile=script.sql

  2. Extract the affected DDL from the written SQLFILE and correct the schema reference. Then execute the command manually.

This is not a good way to do it especially if you have many failed objects and want to automate the process of combining multiple schema for in field upgrading of databases.

Has anyone found a better way to do this? I need a solution that must be 100% reliable if its to be used in the field. I could parse the generated SQL file but can one get this 100% correct? Is there not some way to intercept the CREATE SQL statements execute by IMPDP and correct it on the fly while importing? Could one patch the DMP file directly?

Over to you.

A: 

You could look a DBMS_METADATA

There's a REMAP_SCHEMA option for that. Not sure whether it will work any better than DATAPUMP (and I'd suspect that DATAPUMP would use DBMS_METADATA under the covers). But it would be easier to 'post-process' the output.

Gary
I've checked and, even in 11gR2, DBMS_METADATA REMAP_SCHEMA transform will only affect the schema owning the object, and not explicitly specified schemas of objects referenced within the code/object definition (except where a column has a user-defined type with an explicit schema name, when it does get transformed).
Gary