#!/bin/bash
# Connect to DB and spool query result into a CSV file
sqlplus -s user/password@instance << EOF
set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep ,
spool output.csv
select emp_no, emp_name from emp;
spool off;
exit;
EOF
# Using while loop read values into variables from CSV file and create flat file for each records
counter=1
while IFS=, read V1 V2
do
echo "${V1} ${V2}" > param_${counter}.txt
counter=$(( counter + 1 ))
done < output.csv
i need to assign each coloumn valuse to one variable like above and all these values need to append in one file (Param_Create.prm)...
i am trying with your previous example but i am getting error with '$$' symbols please tell me is there any other way we can concat that symobl to output result before appending to file...
Please help me on this....
I am trying to execute this script, it is executing but it is not generating values to actual flat file, but it wil generate values into .log file and .csv file, Please correct me if i went wrong in the code....
#!/bin/bash
# Connect to DB and spool query result into a CSV file
filepath="/sqlany_data/infa_shared/Scripts/masaga"
DBUSER='etl_user'
DBPWD='etl_dev'
DB='keymsga'
sqlplus -s $DBUSER/$DBPWD@$DB <<EOF > ${filepath}/Masaga_Param_1226.log
set echo off head off pagesize 0 trimspool on linesize 1000 colsep ,
spool Masaga_Param_var.csv
select EMAIL_USER_NAME,DB_CONN_SCHEMA from Msg_Ks_Paramfiles where WORKFLOW_NAME='wf_Msg_Ks_Start_Build_Feat_Delta';
spool off;
exit;
EOF
while IFS=, read USER_NAME DB_CONN_SCHEMA
do
echo "{\$USER_NAME}" > param_Ks_Build_Feat.txt
echo "{\$$DB_CONN_SCHEMA}" > param_Ks_Build_Feat.txt
done < Masaga_Param_var.csv
and how i should pass query if i want o/p variable value like " $$DB_CONN_SCHEMA=ORACLE"...
Thanks...
Sravan
You don't need that while loop. You can format the result in the SQL itself and spool it to file: param_Ks_Build_Feat.txt Here is the modified code:
sqlplus -s $DBUSER/$DBPWD@$DB << EOF
set echo off head off pagesize 0 trimspool on linesize 1000
spool param_Ks_Build_Feat.txt
select '$USER_NAME=' || EMAIL_USER_NAME || '$$DB_CONN_SCHEMA=' || DB_CONN_SCHEMA
from Msg_Ks_Paramfiles where WORKFLOW_NAME='wf_Msg_Ks_Start_Build_Feat_Delta';
spool off;
exit;
EOF