Search code examples
oraclewhere-clauseclauseexpdp

expdp where clause errors


I'm attempting to do an export dump based on a query clause. The table holds 2.37bil rows and i need to dump a subset of those. Here is my parfile

DIRECTORY=EXPSOURCE
DUMPFILE=obs_fact_%u.dmp
PARALLEL=4
TABLES=schema1.observation_fact
QUERY='schema1.observation_fact:"WHERE concept_cd < ''ICD10CM:N93.0'';"'

This is producing the following error

ORA-31693: Table data object "SCHEMA1"."OBSERVATION_FACT" failed to load/unload and is being skipped due to error:
ORA-00933: SQL command not properly ended

I tired wrapping the concept_cd code in quotations rather than double ' but receiving the same error. I've been researching for awhile now with no advancement.

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production


Solution

  • QUERY clause is wrong because:

    • you don't enclose it into single quotes
    • you don't have to use two single quotes around strings
    • you don't terminate the WHERE clause with a semi-colon

    which means that something like this should work:

    QUERY=schema1.observation_fact:"WHERE concept_cd < 'ICD10CM:N93.0'"
    

    Here's an example based on Scott's schema: parameter file (which looks similar to yours; I can't use the PARALLEL option as I'm on 11gXE):

    directory=ext_dir
    dumpfile=obs_fact_%u.dmp
    
    tables=dept
    query=dept:"where dname < 'VANCOUVER:N93.0'"
    

    Execution:

    c:\Temp>expdp scott/tiger@xe  parfile=parfile_01.txt
    
    Export: Release 11.2.0.2.0 - Production on ╚et Srp 26 22:15:41 2018
    
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
    Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/********@xe parfile=parfile_01.txt
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 64 KB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "SCOTT"."DEPT"                              5.929 KB       4 rows
    Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
      C:\TEMP\OBS_FACT_01.DMP
    Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 22:15:44
    
    
    c:\Temp>