0

I am trying to use oracle data pump to export rows of table because the table contains CLOB column and import them to another db. I have linux shell which is used to run the expdp query. The only thing is that for my query i want to select data after a period of time which i get this from db. So i have the RETDATE as a variable which is used to call sqlplus in order to get that value in the form of YYMM and then i will use it inside the data pump query.

My question is that RETDATE is a string can i have variables inside or should they be concatenated like for example in sql we use the || ?? For example i have

RETDATE=`sqlplus $USERNAME/$PASSWORD@$INSTANCE`

Username and Password are used to connect to the database and $INSTANCE is the dname but below i have

SELECT hire_date FROM table@$ANOTHERINSTANCE; 

where $ANOTHERINSTANCE is the db link name used to get the value of the date.

The second part of the question is that if the TO_TIMESTAMP('$RETDATE','YYMM') valid inside the query. This is the code i am thinking to use. Will something like this work??

USERNAME=myname
PASSWORD=pass
INSTANCE=dbinstance
ANOTHERINSTANCE=dblinkname

RETDATE=`sqlplus $USERNAME/$PASSWORD@$INSTANCE <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT hire_date FROM table@$ANOTHERINSTANCE;
EXIT;
EOF`

QUERY='employees:"WHERE hire_date > TO_TIMESTAMP('$RETDATE','YYMM')"' 
PATH=/tmp/test
expdp $USERNAME/$PASSWORD@$INSTANCE directory=EXPORT_DIR tables=hr.employees query=$QUERY dumpfile=$PATH/employees.unl content=data_only logfile=employees.log
4
  • 1
    There is no such thing as a “linux variable”! Are you talking about bash? Commented Apr 1, 2014 at 15:29
  • Yes. When you are writing a .sh script and refer to a variable as RETDATE=something and you can echo using echo $RETDATE. Commented Apr 1, 2014 at 15:44
  • 1
    I don't think you can expand variables inside single quotes so you may have to use some string addition to build your QUERY. Commented Apr 1, 2014 at 19:04
  • Please correct me if i am wrong. The Retdate doesnt have a problem since its inside backticks. Or should i enclose in " the variables such as username pass instance qnd another instance. Now for the Query is the part where i have to concatenate strings in order to include the variable retdate but also preserve the single quotes Commented Apr 1, 2014 at 22:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.