Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, hima bindu.

Asked: February 08, 2018 - 3:37 pm UTC

Last updated: February 01, 2021 - 1:52 am UTC

Version: Release 11.2.0.4.0

Viewed 10K+ times! This question is

You Asked

Good Morning..!!

Q: I've come up with a requirement where I will need to do table export where status ='YES'. My requirement is to get this WHERE clause from input table into variable and put it at expdp command in shell script

Ex: SELECT * FROM T1 WHERE STATUS ='YES'

UPDATE INPUT_TABLE SET SQL_STATEMENT='SCOTT.T1:"WHERE STATUS ='YES'"'

I've tried it with three options.

Option #1.. shell script has below code and run it on Linux server

#!/bin/ksh
V_QUERY=`sqlplus -s ""${DB_STRING}"" <<-EOS
set timing off head off feed off
SELECT SQL_STATEMENT
FROM INPUT_TABLE;
exit;
EOS
`
nohup expdp $DBUSERNAME/$DBPASSWORD@$ORACLE_SID tables=SCOTT.T1 query=$V_QUERY DIRECTORY=exp_dir
JOB_NAME=EXPORT_2018 DUMPFILE=expdp_PROD_2018.dmp LOGFILE=EXPLOG_2018 2>&1 &

I ran the script and got the below error..

ORA-31693: Table data object "SCOTT"."T1" failed to load/unload and is being skipped due to error:
ORA-00904: "YES": invalid identifier

PLEASE SUGGEST IS THERE ANY SYNTAX ERRORS ?

Option #2:

$ expdp UNAME/PWD@DBNAME query=SCOTT.T1:"WHERE STATUS ='YES'" tables=SCOTT.T1

I ran the expdp command and got below error.
ORA-39001: invalid argument value
ORA-39035: Data filter SUBQUERY has already been specified.

Option #3:

It is through .par file

directory=exp_dir
dumpfile=T1.dmp
logfile=T1.log
tables=SCOTT.T1
QUERY=SCOTT.T1:"WHERE STATUS = 'YES'"

$expdp UNAME/PWD@DBNAME parfile=input_par.par

I ran the above command and it works fine as expected.

Finally, I wanted to get subquery from input table but not from the input file. Please suggest and let me know If you need any details.

Thanks
Hima


and Connor said...

Generally when you get errors on the command line with data pump, it is the interaction of the OS shell that is causing problems (ie, mis-interpretation of quotes etc).

For example, this works on the command line:

expdp scott/tiger directory=TEMP dumpfile=test.dmp logfile=expdp.log query='SCOTT.EMP:"WHERE deptno=0",SCOTT.DEPT:"WHERE deptno=0"'

but put some of those entries in shell variables, and you head into quote escapes etc etc.

I would not dismiss Option 3 as the preferred option. Use SQL to generate the par file, and then run expdp with the parfile. That avoids all the hassles.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

It is Solved

hima bindu baddila, February 09, 2018 - 3:09 pm UTC

Thanks, Connor McDonald for your timely response.

I will try it as you suggested.

Option to test

Racer I., February 12, 2018 - 8:57 am UTC

Hi,

Maybe exporting via a view (with the filter inside) may be an option?

Together with :
http://www.dba-oracle.com/Oracle12c/oracle12c_expdp_view_as_tables.htm

regards,

expdp query for selective table

Santosh Vijayan, January 29, 2021 - 5:23 am UTC

Thanks Connor...

I have a requirement to export almost all of table data in a schema. However for some tables data need to be filtered out. I understand this can be done with query clause in expdp. But can I have rest of the tables entire data and selective data for few tables in a single expdp command...

Connor McDonald
February 01, 2021 - 1:52 am UTC

Yes you can control it at a table level. Best to use a PARFILE because of the nested quotes etc, buyt for example:

expdp scott/tiger schemas=scott ... query='SCOTT.EMP:"where empno>0",SCOTT.DEPT:"where loc is not null"'


More to Explore

Utilities

All of the database utilities are explained in the Utilities guide.