How to use QUERY in expdp to extract only the last

2019-08-09 22:32发布

问题:

In my other thread, I have asked how to extract only the last 3 months. However, I managed to extract data from the last 3 months only from one table and it extracted all data for other tables. I have several tables in my schema and the column names for the timestamp are different.

In my par file I have the following QUERY but it did not work. I got ORA-00911 error message. I would like to know if the syntax of the below query is correct/possible .

    QUERY=TABLE1,TABLE2:"where TABLE1_STARTTIME >= TO_DATE('01-AUG-2015','dd-mon-yyyy') and TABLE2_STARTIME >= TO_DATE('01-AUG-2015','dd-mon-yyyy');" 

回答1:

QUERY=TABLE1,TABLE2:"where ... TO_DATE('01-AUG-2015','dd-mon-yyyy');"

Remove the semi-colon in the QUERY parameter.:

QUERY=TABLE1,TABLE2:"where TABLE1_STARTTIME >= TO_DATE('01-AUG-2015','dd-mon-yyyy') 
                     and TABLE2_STARTIME >= TO_DATE('01-AUG-2015','dd-mon-yyyy')" 

On a side note:

Not directly related to your issue. But remember TO_DATE is NLS dependent. You should specify the NLS_DATE_LANGUAGE, else your query might fail for a different nls_date_language.

For example,

SQL> alter session set nls_date_language='FRENCH';

Session altered.

SQL> SELECT TO_DATE('01-AUG-2015','dd-mon-yyyy') FROM DUAL;
SELECT TO_DATE('01-AUG-2015','dd-mon-yyyy') FROM DUAL
               *
ERROR at line 1:
ORA-01843: not a valid month


SQL> SELECT TO_DATE('01-AUG-2015','dd-mon-yyyy', 'nls_date_language=ENGLISH') FROM DUAL;

TO_DATE('01
-----------
01-AO█T -15

I would prefer using ANSI Date literal, when you do not have any time portion. It is NLS independent. It uses a fixed format YYYY-MM-DD.

For example,

SQL> alter session set nls_date_language='FRENCH';

Session altered.

SQL> SELECT DATE '2015-08-01' FROM DUAL;

DATE'2015-0
-----------
01-AO█T -15

SQL> alter session set nls_date_language='AMERICAN';

Session altered.

SQL> SELECT DATE '2015-08-01' FROM DUAL;

DATE'2015
---------
01-AUG-15


标签: oracle expdp