How to redirect value from sql select statment to unix variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to redirect value from sql select statment to unix variable
# 1  
Old 12-04-2006
How to redirect value from sql select statment to unix variable

Hi,

I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use..

Please can any body help me in this regards

Thanks & Regards
Abdul Hafeez Shaik
# 2  
Old 12-04-2006
Something like :
Code:
 mysql -h localhost -P 33060 -u root -p password \"select status from MyData where size=1000 > tomyfile.txt

? What do you mean by variable ?
# 3  
Old 12-04-2006
Thanks for the replay,

I want to get the out put of the select statment into a variable,

export v_sys =0
export v_che =0

After delcaring i want get the out put of the follwing select statment into v_sys variable

select 6 from dual

Thanks & Regards
Abdul Hafeez Shaik
# 4  
Old 12-04-2006
use this

v_syse=`${ORACLE_HOME}/bin/sqlplus -s user_id/password <<END
select 6 from dual ;
EXIT;
END`

--Manish Jha
# 5  
Old 12-04-2006
Thank you

Thank you Manish,

I will try this in my script and let you know.


Regards
Abdul Hafeez Shaik
# 6  
Old 12-05-2006
Hi All

I have tried the following script but am not getting any output, can any one help me to know the problem in my script

export v_test=0
v_test='sqlplus -s apps/apps <<END
set feedback off
set heading off
select 6 from dual;
EXIT;
END'
echo out put is $v_test

Thanks & Regards
Abdul Hafeez Shaik
# 7  
Old 12-05-2006
use like this

v_test=$(sqlplus -s apps/apps <<END
set feedback off;
set heading off;
select 6 from dual;
EXIT;
END)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute sql statment in korn shell

I am fairly new to writing scripts, and have gotten a lot of help from this site in the past with many of the posts. I have a question/issue with a script I am attempting to write and have a question regarding executing an sql statement inside of a loop (do while). I have in the past written... (1 Reply)
Discussion started by: josbor01
1 Replies

2. Shell Programming and Scripting

SQL output to UNIX variable

I have a sql statement , i need to assign to a variable in Unix sel count(*) AS num_files from TABLE_A; i need to use "num_files" in unix statements. let me know how to assign unix variable to above num_files (1 Reply)
Discussion started by: nani1984
1 Replies

3. Shell Programming and Scripting

UNIX variable to SQL statement

The following is my script : #!/bin/bash echo "please give app_instance_id" read app_instance_id echo "id is $app_instance_id" export app_id=app_instance_id sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 @test.sql<<EOF SPOOL /home/tibco/MCH/Data/qa/raak/name.xls... (4 Replies)
Discussion started by: raakeshr
4 Replies

4. Shell Programming and Scripting

Redirect output from SQL to unix variable

Hi, I have a requirement to store oracle sqlplus output to some unix variable, count the records and then print the output on the screen. Can you please point me to any sample program for reference purpose. Thanks a lot for your time. (0 Replies)
Discussion started by: bhupinder08
0 Replies

5. Shell Programming and Scripting

Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All, I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2. I want to assign the output of a select count(*) from tablename to a unix variable in a shell script. I am using ksh. The database used to... (3 Replies)
Discussion started by: Siddarth
3 Replies

6. Shell Programming and Scripting

I want to get the Unix variable value in the sql stmt

Hi All I have a requirement where in I am stuck. There is a shell script that is being developed by me. It consist of the sql stmt also. I need to export a variable called HOMEPAGE with a value say www.abc.com. and then use this $HOMEPAGE variable in the sql stmt. My ultimate aim is to fetch all... (1 Reply)
Discussion started by: amitsinha
1 Replies

7. UNIX for Dummies Questions & Answers

using unix variable in select column in awk

Hi, I have file on below pattern, and i want to write a generic awk to handle all cases. input_file: col1~col2~col3~col4~col5~col6 I need to generate 4 files something like this File1: col1~~col2~~col3 File2: col1~~col2~~col4 File3: col1~~col2~~col5 File4: col1~~col2~~col6 (1 Reply)
Discussion started by: luckybalaji
1 Replies

8. Shell Programming and Scripting

Redirect Postgresql Select Query to Variable

How to redirect postgresql select query to a variable using shell scripts? I tried to use psql -c "select ip from servers" db | egrep '+\.+\+\+' | sed 's/^ *\(.*\) *$/\1/' Output: 10.10.10.180 10.10.10.181 It display ip addresses from the databasem, but how could i redirect the... (3 Replies)
Discussion started by: uativan
3 Replies

9. UNIX for Dummies Questions & Answers

select count(*) in sqlplus into variable unix shell

Need to select count(*) from table to check for zero result in unix script (2 Replies)
Discussion started by: struggle
2 Replies

10. Shell Programming and Scripting

sql query variable not exactly unix

I know htis isnt exactly unix.... but hopefully someone can help me or direct me someplace to get help. I can run sql queries in scripts against my informix db using: dbaccess mydb myquery.sql >> sql.output I need to write my script to select based on todays date. Its very... (5 Replies)
Discussion started by: MizzGail
5 Replies
Login or Register to Ask a Question