Want to use the output of Select statement in Unix script

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Want to use the output of Select statement in Unix script
# 1  
Old 05-23-2005
Want to use the output of Select statement in Unix script

Hi,
I have a UNIX script which calls SQL Select statement:

Now i want to use the output of that select statement within my UNIX script so as to call different shell script depending upon the output of the select statement.

Can anyone help me in this regard.

TIA

Akhil Goel
# 2  
Old 05-23-2005
Quote:
Originally Posted by akhilgoel9
Hi,
Can anyone help me in this regard.
Yes.....

.....if you post the contents of the script that you're using.

Cheers
ZB
# 3  
Old 05-23-2005
Want to use the output of Select statement in Unix script

Please have a look on the below example so as to let you know what exactly i need...


Shell Script:

echo " You are in shell script"

# Start of SQL

str=`sqlplus sa/sa <<eof!
set verify off
set heading off
set feedback off
Select * from table_case;
exit
eof!
`
# End of SQL

i would like to have the output of the above SQL query here..
# display result of above query
echo ???


i dont want to use stored proc
# 4  
Old 05-23-2005
UNIX and SQL

Also see if the below example is possible: can the variable of shell scripts (e.g. count) be accessible in SQL block, If yes then how?

Shell Script:

read count

# Start of SQL

str=`sqlplus sa/sa <<eof!
set verify off
set heading off
set feedback off
Select * from table_case where id = $count;
exit
eof!
`
# End of SQL
# 5  
Old 05-27-2005
If you want to send values to a SQL script as a command line parameter then call your sqlplus command with arguments as follows

sqlplus username/password argument1 argument2 ..

and within the sqlplus commands refer to the arguments as positional parameters as &1, &2 ..

Also if you want to send values from the sql scripts back into the calling environment you would have to write PL/SQL blocks coded into sql scripts which can communicate values from the sqlplus exeuctions as bind_variables. Then you can use the exit command as follows within the PL/SQL block and pass the bind variable back to the calling environment.

EXIT :BIND_VAR;

Jerardfjay
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 print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

2. Shell Programming and Scripting

Problem with select statement

Hi I have run out of ideas as to why this select doesn't work in a script I am writing. The script sources a file of common functions and I am trying to use a select statement within one of the functions - PS3="Try? " select X in CONT EXIT; do if ] ... (4 Replies)
Discussion started by: steadyonabix
4 Replies

3. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies

4. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

5. Shell Programming and Scripting

Unix shell command output to a sql statement

Can i do this Say one command sed 's/:*/ /g' $summf is returning C1234 C2345 C3434 some no of rows, now this ouput i have to insert it into a DB table how do i do this?? (2 Replies)
Discussion started by: depakjan
2 Replies

6. Shell Programming and Scripting

Running a select script through UNIX and sending output to file

Hi, (Oracle, AIX) I have googled this and searched this forum, however I haven't had much luck with an answer and have tried several different things. Basically I have a SQL select statement which generates a whole load of UPDATE statements, I want to run the select statement via... (13 Replies)
Discussion started by: dbchud
13 Replies

7. Shell Programming and Scripting

Select variable within a if statement

i want to select a variable created and use it in a if statement, but not getting the desired results LINE='device for 0101a01: lpd://172.25.41.111:515' prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7` echo $prt My if statement to select just what i want.. IFS=$":" while read prt... (11 Replies)
Discussion started by: ggoliath
11 Replies

8. Shell Programming and Scripting

using SELECT sql statement in shell script

Hi there I have a database on a remote box and i have been using shell script to insert data into it for example, i could have a script that did this SN=123456 n=server1 m=x4140 sql="UPDATE main SET hostname='$n',model='$m' WHERE serial='$SN';" echo $sql |/usr/sfw/bin/mysql -h... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. Shell Programming and Scripting

Supress ' quotes in a select statement inside Shell Script

Hi I have a shell script in which a string variable is saving following query. SqlQuery="select a||'|'||b||'|'||c from dual" I am trying to pass above query as a parameter to some script but its giving me error for "single quote". I tried suppressing it using \' instead of just ' but it... (1 Reply)
Discussion started by: mahabunta
1 Replies

10. UNIX for Dummies Questions & Answers

Pipe SQL select statement results to script

Hello I would like to perform a select from a oracle table and return those values to my shell script For example: site=head -1 $infile | cut -c1-15 | awk '{printf "s%", $0} sqlplus -s /nolog |& #Open pipe to sql select col1, col2, col3, col4 from oracle_table where col5 =... (6 Replies)
Discussion started by: houtakker
6 Replies
Login or Register to Ask a Question