The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 10:28 PM
How to pass unix variable to SQLPLUS chiru UNIX for Advanced & Expert Users 1 06-10-2006 02:11 AM
How to pass variable to SQLPLUS in a ksh script? rwunwla Shell Programming and Scripting 6 05-25-2006 05:41 PM
How to pass Shell variables to sqlplus use them as parameters Jtrinh Shell Programming and Scripting 1 07-13-2005 04:15 AM
To Read a text file using shell Programming sandytul UNIX for Dummies Questions & Answers 1 04-11-2001 11:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2008
Hemamalini Hemamalini is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
To pass the .sql file as a paramter to sqlplus through shell programming

Hi,

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

can anyone pls help me as its very urgent pls.

Thanks,
Hema.

Last edited by Hemamalini; 06-17-2008 at 04:39 AM..
  #2 (permalink)  
Old 06-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
use a here document
Code:
sqlplus -s user/pswd@somedb <<EOF
START 1.sql
EXIT
EOF
START is pretty much the same as @.
  #3 (permalink)  
Old 06-17-2008
Hemamalini Hemamalini is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Question Urgent pls help

Hi Thanks for your Reply.

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

can anyone pls help me as its very urgent pls.

Thanks,
Hema.
  #4 (permalink)  
Old 06-17-2008
kamalesh.p kamalesh.p is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Smile chk once ur parameters

hi

chk ur parameters passing to ur scripts ..

./hema.sh path/sqlfile.sql path/sqlfile.csv

$1 is path/sqlfile.sql
$2 is path/sqlfile.csv

parameter passing will be like this
myscript.sh first second third

but u have taken in reverse
$1 is ur spool file
$2 is ur sql file to be ran

parameter u used in
spool ${filename}
@${sqlfile}


try like this
./hema.sh path/sqlfile.csv path/sqlfile.sql
  #5 (permalink)  
Old 06-17-2008
Hemamalini Hemamalini is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Hi Kamalesh

Kamalesh,

thanks for noticing that error.

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


Thanks,
Hema.
  #6 (permalink)  
Old 06-17-2008
kamalesh.p kamalesh.p is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Smile

hemamalini,

i guess the prob is with the variables that ur using,....

unix is case sensitive ...chk the variables u r using ....

some r in title case .....and some r in lower case,....




Thanks
kamalesh.


Quote:
Originally Posted by Hemamalini View Post
Kamalesh,

thanks for noticing that error.

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


Thanks,
Hema.
  #7 (permalink)  
Old 06-17-2008
hanu_oracle hanu_oracle is offline
Registered User
  
 

Join Date: Mar 2008
Location: MUMBAI, INDIA
Posts: 41
Hai Hema,

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`

X=`echo $RETVAL | grep KeepThis | awk '{print $2}'`
Y=`echo $RETVAL | grep KeepThis | awk '{print $3}'`

echo " " >> $USER_LOG
echo "Procedure: ODS_SP_REMOVE_PRE_SUB_DUP output is: " >> $USER_LOG.CSV
echo "OUT_STATUS= $X" >> $USER_LOG.CSV
echo "OUT_MSG= $Y " >> $USER_LOG.CSV



Note: You need to create the CSV file before call the Oracle Procedure.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0