I want to import a .csv file into an oracle database table below, but its not working and the log file is empty without no output.
my shell script is below:
and also the logfile is always empty
below is a sample of the .csv file
SendingFri,LoggingTime,RenewalNumber,TransactionType,Status,Duration
22997186945,2023-07-25-00:05:56.301,23900032093333,Payment,SUCCESS,null
22951547347,2023-07-25-00:04:12.794,23900336289912,Payment,SUCCESS,null
#!/bin/bash
# Oracle Database Connection Details
USERNAME='abc'
PASSWORD="abc"
HOST="myip"
PORT="1521"
SERVICE_NAME="abc"
# CSV File Details
CSV_FILE="/home/hdegboevi/modified5.csv"
TABLE_NAME="myCANALINFORMATION"
# Control File
CONTROL_FILE="my_control_file.ctl"
# Create a control file
cat <<EOF > $CONTROL_FILE
LOAD DATA
INFILE '$CSV_FILE'
APPEND INTO TABLE $TABLE_NAME
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
SENDINGFRI,
LOGGINGTIME,
RENEWALNUMBER,
TRANSACTIONTYPE,
STATUS,
DURATON
)
EOF
# Run SQL*Loader
sqlldr $USERNAME/$PASSWORD@$HOST:$PORT/$SERVICE_NAME control=$CONTROL_FILE log=/home/hdegboevi/sqlldr.log /home/hdegboevi
# Check the log for errors
if grep "ORA-" sqlldr.log; then
echo "Error occurred during data load. Please check sqlldr.log for details."
else
echo "Data loaded successfully."
fi
You should have posted target table description; without it, we have to guess datatypes. My lucky guess (according to sample data):
which is probably wrong;
durationcolumn sounds as if you'd want to put e.g. a number in it (something took 2 seconds to complete), but sample data suggests that you're inserting a string into it (null, in this context, is a string).With a control file you wrote, result is (in my database)
Control file, fixed:
Loading session:
Result:
OK; data is here.
I'd suggest you to first make that part of job correctly (i.e. loading itself), and then create a shell script. I can't assist about that, I don't use any kind of Unix operating systems.
[EDIT, after you posted table description]
Aha; so all columns are
varchar2. Even simpler.(I thought it was a typo, "duraton" vs. "duration"; looks like it really is "duraton", whatever that might be).
Control file is trivial:
Loading session:
Result: