Pages

Tuesday, March 13, 2012

On ORA-14400: inserted partition key does not map to any partition using ImpDp (Data Pump)

After I have exported my partitioned tables I had to import into development database.
The command I used was (the dmp file was located on default DATA_PUMP_DIR directory):
impdp system@MY_DEV_INSTANCE dumpfile=20120312_SCHEMANAME_TABLENAME.dmp TABLE_EXISTS_ACTION=TRUNCATE

but the following error was found:
ORA-14400: inserted partition key does not map to any partition

This happens when some datas have to be inserted into a partition but that partition doesn't exist. My SCHEMANAME.TABLENAME table was already created last month but impdp was not able to create the missing partitions.
I solved simply dropping and creating again my table from the dump itself with the following command:
impdp system@MY_DEV_INSTANCE dumpfile=20120312_SCHEMANAME_TABLENAME.dmp sqlfile=SCHEMANAME_TABLENAME.ddl


Then I modified the SCHEMANAME_TABLENAME.ddl file adding a "future" partition:
CREATE TABLE "SCHEMANAME"."TABLENAME"
( ....
....
)
TABLESPACE "TSD_SCHEMANAME"
PARTITION BY RANGE ("CALLDATA")
( ....
....
PARTITION "P20120311" VALUES LESS THAN (TO_DATE(' 2012-03-12 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLESPACE "TSD_SCHEMANAME" COMPRESS ,
PARTITION "P20120312" VALUES LESS THAN (TO_DATE(' 2012-03-13 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLESPACE "TSD_SCHEMANAME" COMPRESS,
PARTITION P20150101 VALUES LESS THAN (MAXVALUE)
TABLESPACE "TSD_SCHEMANAME" COMPRESS);


In this way the second attempt to complete the import worked as expected.

On ORA-00911: invalid character and LRM-00123: invalid character 128 found using ExpDp (Data Pump)

Few days ago I received a task to export and import some partitioned tables from a production database to a development one.
They sent me a mail with a WHERE CLAUSE to filter exclude some data.
I copied and pasted that WHERE CLAUSE on my linux terminal and written the following expdp command:
expdp system@MY_RAC_INSTANCE1 DUMPFILE=20120312_SCHEMANAME_TABLENAME.dmp TABLES=SCHEMANAME.TABLENAME EXCLUDE=STATISTICS query=\"where trunc\(CALLDATE\) \>\= to_date\(\‘20120312\’\,\’YYYMMDD\’\)\"

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_02": system/********@MY_RAC_INSTANCE1 DUMPFILE=20120312_SCHEMANAME_TABLENAME.dmp TABLES=SCHEMANAME.TABLENAME EXCLUDE=STATISTICS query="where trunc(CALLDATE) >= to_date(‘20120101’,’YYYMMDD’)"
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 20.24 GB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
ORA-31693: Table data object "SCHEMANAME"."TABLENAME":"P20080110" failed to load/unload and is being skipped due to error:
ORA-00911: invalid character


I received hundred of the above error before stopping the export job. That error usually happens when your WHERE CLAUSE is wrong: I was quite sure it was not... but it didn't work so I suddendly created a parfile to limit the error's analysis.
The following was my parameter file (named parfile.txt):
DUMPFILE="20120312_SCHEMANAME_TABLENAME.dmp"
LOGFILE="20120312_SCHEMANAME_TABLENAME.log"
DIRECTORY=DATA_PUMP_DIR
COMPRESSION=NONE
CONTENT=ALL
QUERY="where trunc(CALLDATE) >= to_date(‘20120101’,’YYYMMDD’)"
EXCLUDE=STATISTICS
TABLES=('SCHEMANAME."TABLENAME"')


and I execute it with the following command:
expdp system@MY_RAC_INSTANCE1 parfile=parfile.txt


I obtained the following error:
[oracle@my_hostname DDL]$ expdp system@MY_RAC_INSTANCE1 parfile=parfile.txt 
LRM-00123: invalid character 128 found in the input file
LRM-00113: error when processing file 'parfile.txt'


Looking at the characters of parfile.txt I discovered where was the error:
to_date(‘20120101’,’YYYMMDD’) would have to be written as to_date('20120101','YYYMMDD')...
Backtick and tick were written during my copy and paste command.

My parfile was now as the following:
DUMPFILE="20120312_SCHEMANAME_TABLENAME.dmp"
LOGFILE="20120312_SCHEMANAME_TABLENAME.log"
DIRECTORY=DATA_PUMP_DIR
COMPRESSION=NONE
CONTENT=ALL
QUERY="where trunc(CALLDATE) >= to_date('20120101','YYYMMDD')"
EXCLUDE=STATISTICS
TABLES=('SCHEMANAME."TABLENAME"')


but it was still not sufficient to complete the export because of this error:

ORA-31693: Table data object "SCHEMANAME"."TABLENAME":"P20080110" failed to load/unload and is being skipped due to error:
ORA-29913: error in executing ODCIEXTTABLEPOPULATE callout
ORA-01843: not a valid month


And of course... 'YYYMMDD' is not a valid month when used to translate the date '20120101' !!!

My parfile.txt was corrected as the following:
DUMPFILE="20120312_SCHEMANAME_TABLENAME.dmp"
LOGFILE="20120312_SCHEMANAME_TABLENAME.log"
DIRECTORY=DATA_PUMP_DIR
COMPRESSION=NONE
CONTENT=ALL
QUERY="where trunc(CALLDATE) >= to_date('20120101','YYYYMMDD')"
EXCLUDE=STATISTICS
TABLES=('SCHEMANAME."TABLENAME"')


and it worked.
I tested also the first command line and it worked too:
expdp system@MY_RAC_INSTANCE1 DUMPFILE=20120312_SCHEMANAME_TABLENAME_test.dmp TABLES=SCHEMANAME.TABLENAME EXCLUDE=STATISTICS query=\"where trunc\(CALLDATE\) \>\= to_date\(\'20120312\'\,\'YYYYMMDD\'\)\"


Next time I won't copy and past anything from mail...