Currently i have a .sql file 1.sql.
I need to pass that as a parameter through a shell script to the sqlplus inside the same shell script.
How I should I do.can anyone help me pls.
I have an req where I need to send the .sql file and the place where the script has to create a .csv file with the out of the query as a parameter when the shell script is called.
Currently My script looks like this.
#!/bin/ksh
set timing on
Filename $1
Sqlfile $2
sqlplus -S username/Pwd@dbname<<EOF
set timing off heading on feedback off pagesize 0 linesize 250
WHENEVER SQLERROR EXIT FAILURE
WHENEVER OSERROR EXIT FAILURE
spool ${filename}
@${sqlfile}
spool off;
Exit;
EOF
I am calling the script like this
./hema.sh path/sqlfile.sql path/sqlfile.csv
But I am getting an error stating
ld.so.1: sqlplus: fatal: libclntsh.so.9.0: open failed: No such file or directory
But I have an req where I need to send the .sql file and the place where the script has to create a .csv file with the out of the query as a parameter when the shell script is called.
Currently My script looks like this.
#!/bin/ksh
set timing on
Filename $1
Sqlfile $2
sqlplus -S username/Pwd@dbname<<EOF
set timing off heading on feedback off pagesize 0 linesize 250
WHENEVER SQLERROR EXIT FAILURE
WHENEVER OSERROR EXIT FAILURE
spool ${filename}
@${sqlfile}
spool off;
Exit;
EOF
I am calling the script like this
./hema.sh path/sqlfile.sql path/sqlfile.csv
But I am getting an error stating
ld.so.1: sqlplus: fatal: libclntsh.so.9.0: open failed: No such file or directory
Spool concept is not required in the shell scripting. Simply you can create a blank .csv file using `touch` command in unix.
Spool concept is useful only in Windows. what ever you are passing the sqlfile.sql( Input to Script )those are declared in the SQL-Part (Begin - - End;) of the below mentioned code (Execute simple Procedure):
RETVAL=`sqlplus -s USERNAME/PASSWORD@DBNAME <<EOF
SET SERVEROUTPUT ON SIZE 100000
Declare
OUT_STATUS NUMBER;
OUT_MSG VARCHAR2(200);
Begin
ODS_SP_REMOVE_PRE_SUB_DUP(OUT_STATUS, OUT_MSG);
dbms_output.put_line ('KeepThis '||OUT_STATUS ||' '||nvl(OUT_MSG,''));
End;
/
SET SERVEROUTPUT OFF
EXIT;
EOF`
I tried the same way as you told but even then I am getting the same error.
./hema.sh[3]: Filename: not found
./hema.sh[4]: Sqlfile: not found
ld.so.1: sqlplus: fatal: libclntsh.so.9.0: open failed: No such file or directory
./hema.sh[5]: 18041 Killed
I had given choice to u only. U know oracle - - I am only executing the simple Stored Procedure{ODS_SP_REMOVE_PRE_SUB_DUP(OUT_STATUS, OUT_MSG)}. Instead of SP, You can use the simple queries inside the PLSQL loop.
For code re-usability. Take the $1 variable value in the SQL-Query WHERE condition.
If you are perfect in PLSQL, u are make this code very easily & confidently..