Grabbing result of sql command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grabbing result of sql command
# 1  
Old 07-23-2008
Grabbing result of sql command

Hi guys,

Is there a way a script can run an SQL statement and dump the results into a variable which can then be used later in the script?

Thanks.
# 2  
Old 07-23-2008
Try this:
Code:
TABLE_NAME=sometable
USER_NAME=someuser
IP_ADDR=localhost
PASSWORD=somepassword

somevar=`echo "select * from <table_name> where <condition>" | mysql -h $IP_ADDR -u $USER_NAME -p$PASSWD $TABLE_NAME `

echo $somevar

# 3  
Old 07-23-2008
Thanks for the help..

I get the following error:

mysql: not found.

I am using Unix on AIX platform, bin/sh script, and DB2 database.
# 4  
Old 07-23-2008
That was for a mysql database.

Try to Google: db2 shell query
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grabbing value from file and run command in ``

Hi ALL, How can I make a script take data from a file and execute the commands within `` in the file n put that that in a variable? for i in `cat file` do file=`grep -i key file` cp ${file} test done file /tmp/`date +y`log /tmp/unix`date +y`log (1 Reply)
Discussion started by: 3junior
1 Replies

2. Shell Programming and Scripting

[Solved] Using AWK to extract SQL result

I just wish to extract the result onli... but I dont which edit to perform to start from (**) :wall: Current display result SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 24 14:14:49 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g... (4 Replies)
Discussion started by: ment0smintz
4 Replies

3. UNIX for Dummies Questions & Answers

Assign SQL result in shell variable

Hi im trying to assign the result of the db2 command to a variable inside a shell script... : tab_cnt=`db2 "select count(*) from syscat.tables where tabname = 'ABC' and tabschema = 'MATT01'" |head -4|tail +4|cut -c 11` : echo $tab_cnt when i echo im getting a blank value.. im expecting... (1 Reply)
Discussion started by: matt01
1 Replies

4. Shell Programming and Scripting

Grabbing value from command output and monitoring for changes

Hi all, Very new to shell scripting so appreciate some help! There is a process count that I need to monitor, I have the AIX command that gives this value and I've cleaned it up with grep/awk so it only spits out the value I'm interested in: echo "psc -i 10050 -s RELOAD_SERVICE" | tmadmin... (14 Replies)
Discussion started by: monty77
14 Replies

5. Shell Programming and Scripting

How to format sql result as amount - ksh

I am currently returning an sql result with a number value that I want to format as an amount. The sql runs smoothly on its own, but when run inside my ksh script an error is encountered: ERROR at line 3: ORA-01481: invalid number format model My sql is -- select distinct ... (6 Replies)
Discussion started by: avillanueva
6 Replies

6. Shell Programming and Scripting

Help! Paste Multiple SQL output result to exec command

Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ... (0 Replies)
Discussion started by: jackyntk
0 Replies

7. Shell Programming and Scripting

How to assign the result of a SQL command to more than one variable in shell script.

Hi Friends... Please assist me to assign the result of a SQL query that results two column, to two variables. Pls find the below code that I write for assigning one column to one variable. and please correct if anything wrong.. #! /bin/sh no=' sqlplus -s uname/password@DBname... (4 Replies)
Discussion started by: little_wonder
4 Replies

8. Shell Programming and Scripting

formatting the sql select result

Hi, I have about 12 columns and 15 rows to be retrived from sybase isql command through unix. But when i output the sql into a file and see it, the formatting is going for a toss. can someone please suggest how can i get the result correctly in the output file ? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies

9. Shell Programming and Scripting

any possible to run sql result and output to file

Hi, I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file. for example, i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this... (7 Replies)
Discussion started by: happyv
7 Replies

10. Shell Programming and Scripting

how to retrieve sql result to unix....

Hi, i would like to retrieve seql result and write it into unix text file like "result.txt" In unix, normally, I type "sql" and get into sql,then type "select....." to run and get the result....then copy and paste into result.txt any possible way to write a script to run it automatically?... (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question