EXPDP - ORA-39166 (Object Was Not Found) When Trying To Export The Data From A View (Doc ID 1640392.1)

To BottomTo Bottom

In this Document

  Symptoms
  Changes
  Cause
  Solution
  References

 

APPLIES TO: 

Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Information in this document applies to any platform.

NOTE: In the document content below, the user information and data used represents fictitious data .Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner. 

SYMPTOMS

1. You have a user who has created a view, e.g.:

connect / as sysdba
create user tc identified by tc default tablespace users
   temporary tablespace temp quota unlimited on users;
grant create session, create table, create view to tc;

create directory my_dir as '/tmp/expdp';
grant read, write on directory my_dir to system;

connect tc/tc
create table tc.my_tab1 (nr number, txt varchar2(10));
insert into tc.my_tab1 values (1,'Line 1');
insert into tc.my_tab1 values (2,'Line 2');
[Insert code here. Use 'Paste from Word' to retain layout.]
 
create table tc.my_tab2 (nr number, col2 number, col3 varchar2(10));
insert into tc.my_tab2 values (1,1,'c3_1');
insert into tc.my_tab2 values (2,2,'c3_2');
commit;
create view my_view (nr, txt, col3) as
   select t1.nr, t1.txt, t2.col3 
     from tc.my_tab1 t1, tc.my_tab2 t2
    where t1.nr=t2.nr;
select * from my_view;

          NR TXT        COL3
------------ ---------- ----------
           1 Line 1     c3_1
           2 Line 2     c3_2

2. When you export the view with DataPump, then only the DDL of the view is exported, e.g.:

$ expdp system/<password> DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log SCHEMAS=tc INCLUDE=view:\"\=\'MY_VIEW\'\"

Export: Release 11.2.0.4.0 - Production on Thu Mar 27 09:43:13 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log SCHEMAS=tc INCLUDE=view:"='MY_VIEW'"
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
  /tmp/expdp/EXPDP_VW.DMP
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Mar 27 09:43:24 2014 elapsed 0 00:00:10

3. When you try to export the data that is represented by the view by specifying the TABLES parameter, the following errors are reported:

$ expdp system/<password> DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log TABLES=tc.my_view

Export: Release 11.2.0.4.0 - Production on Thu Mar 27 09:47:34 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01":  system/******** DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log TABLES=tc.my_view
Estimate in progress using BLOCKS method...
Total estimation using BLOCKS method: 0 KB
ORA-39166: Object TC.MY_VIEW was not found.
ORA-31655: no data or metadata objects selected for job
Job "SYSTEM"."SYS_EXPORT_TABLE_01" completed with 2 error(s) at Thu Mar 27 09:47:38 2014 elapsed 0 00:00:03

 

CHANGES

 

CAUSE

The Export Data Pump parameter TABLES cannot be used to export the data that is represented with a VIEW.
 

SOLUTION

1. Upgrade to Oracle12c where you can specify the Export Data Pump parameter VIEWS_AS_TABLES (to export a table with the same columns as the view and with row data fetched from the view. Data Pump also exports objects dependent on the view, such as grants and constraints).
Note that this is a new feature in 12c which does not exist in 11g. Example:

$ expdp system/<password> DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log VIEWS_AS_TABLES=tc.my_view

Export: Release 12.1.0.1.0 - Production on Thu Mar 27 08:38:07 2014
Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01":  system/******** DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log VIEWS_AS_TABLES=tc.my_view
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA
Total estimation using BLOCKS method: 16 KB
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE
. . exported "TC"."MY_VIEW"                              5.906 KB       2 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
  /tmp/expdp/expdp_vw.dmp
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at Thu Mar 27 08:38:29 2014 elapsed 0 00:00:17

-- or --

2. Create a fixed table in the source database which contains the rows that you want to export (the rows from the view), e.g.

create table tc.my_view_tab as select * from tc.my_view;
 

and export the data from the temporary fixed table, e.g.:

$ expdp system/<password> DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log TABLES=tc.my_view_tab

-- or --

3. Export all source tables (all rows) and all other related objects, e.g.:

$ expdp system/<password> DIRECTORY=my_dir DUMPFILE=expdp_vw.dmp LOGFILE=expdp_vw.log SCHEMAS=tc INCLUDE=table:\"IN\(\'MY_TAB1\',\'MY_TAB2\'\)\" INCLUDE=view:\"\=\'MY_VIEW\'\"

 

REFERENCES

NOTE:341733.1 - Export/Import DataPump Parameters INCLUDE and EXCLUDE - How to Load and Unload Specific Objects