storing database query in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting storing database query in a variable
# 1  
Old 11-21-2007
storing database query in a variable

I am executing a SQL query in Unix Server:
select status,location from user_information where request_id='DS-43720'

In shell script I am writing this query in the below manner:

echo "select status,location from user_information where request_id='DS-43720' ;" >> $directory/info.sql

//(here $directory is my home folder in Unix Server)

echo "EXIT" >> $directory/info.sql

sqlplus -s $sUserId/$sUserPassword@$ORACLE_SID @$directory/info.sql 1>>$directory/info.log 2>>$directory/info.log

Now how do I store those two column values returned in Sql query in a Unix Variable??
# 2  
Old 11-21-2007
Show us what the output looks like and we can probably come up with something. In the meantime, I'd suggest that you want something like:
Code:
myvariable=`long-sql-command`

Use of awk and cut should be able to split out the data in the columns.

Without one of the redirects (at a guess, you should still redirect STDERR to the log but stop redirecting STDOUT so the calling script can capture it instead).
# 3  
Old 11-22-2007
can you mention the awk and cut commands format?
# 4  
Old 11-25-2007
Quote:
Originally Posted by debu
can you mention the awk and cut commands format?
You'd need to show us the output that needs splitting up first sorry Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. Programming

Database query

I am getting an error function in date formate while importing the date ccolumn in oracle sql developer tool My date format in table is 6-Nov-14 and while importing its converted to 6/11/14 eventhough the format is as 6-Nov-14 in excel. could you please let help me out what I need to change... (6 Replies)
Discussion started by: ramkumar15
6 Replies

3. Shell Programming and Scripting

Storing the value of a single query to a Variable - What am i doing wrong?

I tried the below : #!/bin/ksh testvar=$( sqlplus $user/$pass << EOF set pagesize 0 feedback off verify off heading off echo off; whenever sqlerror exit 1 SELECT 1+1 FROM DUAl; COMMIT; EXIT; EOF) echo "testvar="$testvar The output that I am getting is : > sh example.sh... (3 Replies)
Discussion started by: SriRamKrish
3 Replies

4. Shell Programming and Scripting

Problems with storing oracle sqlplus query output shell script

Hello everyone, I have a RHEL 5 system and have been trying to get a batch of 3-4 scripts each in a separate variables and they are not working as expected. I tried using following syntax which I saw a lot of people on this site use and should really work, though for some reason it doesn't... (3 Replies)
Discussion started by: rockf1bull
3 Replies

5. Shell Programming and Scripting

Storing information into a database.

Hey guys, i am having a problem in storing new data into a text file. The database in in a text file and it displays information like this : Name : Price : Quantity Persia : 80 : 30 Now , i have written the code to check if the book already exist in the Databse. Number= echo -n... (3 Replies)
Discussion started by: gregarion
3 Replies

6. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

7. Shell Programming and Scripting

Problem while storing sql query value in a variable

Hi, When i execute the below statement , the value is not getting stored in the variable. AnneeExercice=`sqlplus $LOGSQL/$PASSWORDSQL << FIN >> $GEMOLOG/gemo_reprev_reel_data_ventil_$filiale.trc SELECT bi09exercice FROM bi09_scenario WHERE bi09idfiliale=UPPER('de') AND ... (1 Reply)
Discussion started by: krishna_gnv
1 Replies

8. Shell Programming and Scripting

Storing a variable?

I'm writing a bash shell script to backup several mysql databases. This script will run on a daily basis and send a copy to a remote FTP repository. The filenames are in the format DATE.backup.sql. How do I store the DATE variable so I can delete/move/etc the file on the FTP server the next time... (4 Replies)
Discussion started by: hoover90
4 Replies

9. Shell Programming and Scripting

Database Query

Hi, Am using informix database. When i give "isqlrf <database name> - " from the command prompt , i get connected to the database and i can run sql queries.. I am moving to freeBSD and when i give the same command at the prompt i get an error : Index already exists on column Why is this... (0 Replies)
Discussion started by: jisha
0 Replies

10. Shell Programming and Scripting

query to get a value from database

Hi friends, I have written a script which retrieves one value from the database. It takes time for the sql query to get the desired output. So the query runs fine from TOAD or from UNIX console. However if I put this in a script it doesn't work. The script is as below. #! /bin/ksh... (2 Replies)
Discussion started by: vivek_damodaran
2 Replies
Login or Register to Ask a Question