Can we have multiple SQL* PLUS connections in a shell script?
I have written a shell script to copy the data of tables from one database to another using COPY command of SQL* PLUS. I don’t have the privilege to create Database Link so, I am using the COPY command.
I need to copy the data of around 50 tables. When the dataset is small, it runs and copies the data of all the tables. But when the dataset is huge, it gets stuck and I get session inactive message in the unix machine.
I thought of splitting the statements and wrote it as below: But I am getting the error “SP2-0042: unknown command “END1″ – rest of line ignored.” and “SP2-0042: unknown command “END” – rest of line ignored.”
#!/bin/bash
export ORACLE_HOME=/ora00/app/oracle/product/9.2.0.8
export PATH=$PATH:$ORACLE_HOME/bin
args=$#
if [ $args == 1 ]
then
echo "Shell script started"
else
echo "Wrong number of arguments"
exit 1
fi
time_start=`date +%H%M%S`
echo $time_start
sqlplus -s srcUN/srcPwd@srcSID <<END1
COPY from srcUN/srcPwd@srcSID to dstUN/dstPwd@dstSID INSERT tab1 USING SELECT * FROM tab1 WHERE col1 = $1;
COPY from srcUN/srcPwd@srcSID to dstUN/dstPwd@dstSID INSERT tab2 USING SELECT * FROM tab2 WHERE col1 = $1;
END1
sqlplus -s srcUN/srcPwd@srcSID <<END2
COPY from srcUN/srcPwd@srcSID to dstUN/dstPwd@dstSID INSERT tab3 USING SELECT * FROM tab3 WHERE col1 = $1;
END2
#END
Could you please help me resolve this?
Thanks,
Savitha
The problem is that
END1andEND2are not recognized as the end of the input redirection because they have leading whitespace.Remove all the whitespace on these two lines and it should work.