Unable to pass value from .Shell script to .SQL file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to pass value from .Shell script to .SQL file
# 1  
Old 04-29-2015
Unable to pass value from .Shell script to .SQL file

Hi All,
I am new to shell script. I am trying to pass value from .sh file to .sql file .
But I am able to run the .sql file from .sh file with values in sql file.
But I am unable to pass the values from .sh file. can some one please help to resolve this.

here is my .sh file
s1.sh

Code:
#!/bin/ksh[/FONT][/SIZE][/COLOR]
echo "please enter case:"
read v_case_nbr
echo "the case number entered is $v_case_nbr"
sqlplus wmtst/wmtst@wmtest <<EOF
@ test.sql $ v_case_nbr
exit;
EOF

here is .sql file


Code:
 SET SERVERoutput on;
declare 
v_case_nbr varchar(400):='&Enter_Case_nbr';
c_stat_code case_hdr.stat_code%type;

 cursor c1 is select ch.stat_code into c_stat_code from case_hdr ch  where ch.case_nbr=v_case_nbr;
  
 
begin
open c1;
LOOP
FETCH c1 into c_stat_code;
EXIT when c1%notfound;
If (c_stat_code = '50')
then
update case_hdr ch
set ch.stat_code='30',
ch.user_id = 'PILLAREM',
ch.mod_date_time = sysdate 
where ch.case_nbr = v_case_nbr;
dbms_output.put_line('Case_hdr:Case updated To putaway status ');
end if;
 end loop;
 close c1;
 end;
 /

Here I need to pass v_case_nbr='123456' from .sh file to .sql file

Please help me to resolve this.

Thanks a bunch.

Regards,
reddy298599

Last edited by Don Cragun; 04-29-2015 at 01:31 PM.. Reason: Remove FONT, COLOR, and FONT tags; add CODE and ICODE tags.
# 2  
Old 04-29-2015
Please use code tags as required by forum rules!

When calling test.sql, v_case_nbr will not be expanded by the shell as it is separated by a space from the necessary $ .
# 3  
Old 04-29-2015
Unable to pass value from .Shell script to .SQL file

Hi Rudic,

You mean to use .sh file like this.

Code:
 #!/bin/sh
echo "please enter case:"
read v_case_nbr
echo "the case number entered is $v_case_nbr"
sqlplus wmtst/wmtst@wmtest <<EOF
@ test.sql ,v_case_nbr
 exit;
EOF

I am getting error on this. see if you can provide me exact code is greatly apprecited

Last edited by Don Cragun; 04-29-2015 at 01:32 PM.. Reason: Add CODE tags.
# 4  
Old 04-29-2015
Please use code tags as required by forum rules!

Use like $v_case_nbr.
# 5  
Old 04-29-2015
SQL> .sh script calling .sql file with out error.But am getting out as numbers 1 2 3 4 5 .... I am getting out like this. But the output is incorrect
Code:
@ test.sql $v_case_nbr

---------- Post updated at 05:08 AM ---------- Previous update was at 05:06 AM ----------

Here is my scripts
s5.sh
Code:
#!/bin/sh
echo "please enter case:"
read v_case_nbr
echo "the case number entered is $v_case_nbr"
sqlplus wmtst/wmtst@wmtest <<EOF
@ test.sql $v_case_nbr_
 exit;
EOF

test.sql

Code:
declare
 v_case_nbr number;
 
select count(*) from case_hdr where case_nbr=&1;


Last edited by Don Cragun; 04-29-2015 at 01:35 PM.. Reason: Remove ICODE tags around plain text, change ICODE tags around full-line and multi-line code segments to CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Unable to pass send command in shell script

I am trying to automate a testcase . I am installing some software and it waits for user input after displaying "Do you want to continue ? " I am trying to do this in shell scripting. #!/bin/bash #!/usr/bin/expect -f /usr/bin/expect << EOF spawn apt-get install openjdk-7-jdk expect "*Do you... (1 Reply)
Discussion started by: Abdul Navaz
1 Replies

3. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

4. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

5. Shell Programming and Scripting

unable to pass value to user prompt from calling shell script

This is my script structure main script calls configure script which needs to be run as a different user and the configure script calls my application installation script. the application instruction script prompts the user for a directory which I need to pass from my main or configure script. ... (4 Replies)
Discussion started by: cmastays
4 Replies

6. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

7. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

8. Shell Programming and Scripting

How to pass arguments to SQL file passed in shell script?

Hi, I am using SYBASE database. in my script i am connecting to DB via using isql. isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b0 -w3000 -h0 -s"|" -i${MYDIR}/ABC.sql -oXYZ.txt << FINSQL i am taking a ABC.sql file to use the queries written in it and storing the output in... (3 Replies)
Discussion started by: dazdseg
3 Replies

9. Shell Programming and Scripting

How to pass pl/sql table values to shell script

Hello, i am using '#!/bin/bash', i want to make a loop in pl/sql, this loop takes values from a table according to some conditions, each time the loop choose 3 different variables. What i am not able to do is that during the loop i want my shell script to read this 3 variables and run a shell... (1 Reply)
Discussion started by: rosalinda
1 Replies

10. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies
Login or Register to Ask a Question