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...