当先锋百科网

首页 1 2 3 4 5 6 7

开发提出需要从Greenplum同步到Oracle的解决方案,写了个脚本用于定时调度处理。

0818b9ca8b590ca3270a3433284dd417.png

脚本如下:

#!/bin/sh

#copy_gp_2_ora.sh

if [ $# -ne 1 ]; then

echo "Usage: sh $0 tablename"

exit 1

fi

TABLENAME=$1

psql -h -U <

\timing off

set client_encoding='gb18030';

\copy $TABLENAME to '/home/oracle/$TABLENAME.txt' csv

\q

EOF

echo "load data

infile '$TABLENAME.txt' discardfile '$TABLENAME.dis'

append

into table $TABLENAME

fields terminated by ','

optionally enclosed by '\"'

(id)">"$TABLENAME.ctl"

sqlldr system/000000 control="$TABLENAME.ctl" log="$TABLENAME.log"

-EOF-