Linux – Import all csv files into a table oracle

linuxoraclescripting

Trying to import all the files into a table but I receive the following error.

#!/bin/bash 
. ~/.bash_profile 
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1
sqlldr USERID=user/pass@mydb DATA=/data/SDP/Import/*.csv \
    CONTROL=/home/path/test.ctl LOG=/home/path/test.log

Error Message

 SQL*Loader-500: Unable to open file  (/path/path/Import/*.csv) 
 SQL*Loader-553: file not found 
 SQL*Loader-509: System error: No such file or directory 
 SQL*Loader-2026: the load was aborted because SQL Loader cannot  continue.

Please help.

Best Answer

Use a shell loop, instead of trying to pass a wildcard:

#!/bin/bash 
. ~/.bash_profile 
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1

for FILE in /data/SDP/Import/*.csv; do
    sqlldr USERID=user/pass@mydb "DATA=$FILE" \
        CONTROL=/home/path/test.ctl LOG=/home/path/test.log
    done