How to get result of sqlcmd output in variable?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get result of sqlcmd output in variable?
# 1  
Old 01-27-2014
How to get result of sqlcmd output in variable?

Hi All,

I am looking for a solution. I am executing below command in shell script:
SQL= "select count(*) from dual"
sqlcmd --login /oracle/baccess.xml --sql  "$SQL".

I can see the result while executing above shell script. but I want to store the value of query output irrespective the return value 0 or any value. Please help me on this

---------- Post updated at 10:26 AM ---------- Previous update was at 09:46 AM ----------

Hi Everyone,

Any clue on this??

Last edited by Scrutinizer; 01-27-2014 at 11:53 AM.. Reason: code tags
# 2  
Old 01-27-2014
sqlcmd --login /oracle/baccess.xml --sql  "$SQL" > /tmp/sqlcmd.txt

Above command will redirect the query output to

then you grep it or whatever operation you want to perform.
# 3  
Old 01-27-2014
Agreed, it is better to store large things like query outputs it in a file than a variable... Depending on your system, variables may have surprisingly small maximum sizes. Keeping it in a variable also makes it harder to loop inside the shell, harder to use with external utilities, and can cause lots of quoting problems.

But for the record, you can store program output in a variable by doing:

VARIABLE=$( program statement )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning variable to output gives error with expected result

Hello, I am trying to print out the first string matching query with grep and I need your help. My scenario: Database John F 4433 Street No 88 CA Elisabeth Taylor 7733 Street No 26 ON Jack Nicholson 0133 Green Park No 34 AR John F 2 9399 Southpark No 02D UT (6 Replies)
Discussion started by: baris35
6 Replies

2. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

3. UNIX for Advanced & Expert Users

Error executing sqlcmd command through UNIX

Hi All, I am trying to execute a set of sql statements in sql server 2008 using the sqlcmd command in unix and passing the query in the "input" parameter. It is giving me an error "incorrect syntax near 2014". The below statement is giving an error : declare date_val datetime, ... (4 Replies)
Discussion started by: Rahul Raj
4 Replies

4. UNIX for Dummies Questions & Answers

I save the result in a variable

I have friends that this command worked perfectly, but I would like to save the result in a variable, which I have not achieved var=prueba.txt echo $var | cut -d "." -f 1 prueba I need to do this but does not work me salida=echo $var | cut -d "." -f 1 echo "result:$salida" ... (8 Replies)
Discussion started by: tricampeon81
8 Replies

5. Shell Programming and Scripting

Result of 'cut' into variable

Hello, I would like to have a result of a cut-command in a variable. The file "t.dat" has the following content: Company 001.239879123.OB1X.672W12.STS UNOLD.001.02 My bash-script: Header="" Header=$(cut -c1-160 t.dat | head -1) echo $Header ... (9 Replies)
Discussion started by: API
9 Replies

6. Shell Programming and Scripting

How to combine two variable result?

Hi, i have two variables i.e lck_ckm_customer=ckm_customer and(present in some script A) table=ckm_customer(present in script B) in script B i am executing this part if ; then --- ---- ---- fi Now, while comparing in my log file i am getting this result if but i... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

7. Shell Programming and Scripting

result in variable

Hi all, I'll try to get a result from a search with "awk" into a variable. It works for those examples: findfirstline=`awk 'BEGIN{ mycount = 1 } { if(mycount == 1 && /^Video/){ row=NR; print row; mycount = 0; }}' ${i}` findlastline=`awk '/^Video/ {row=NR} END{print row}' ${i}` But it... (6 Replies)
Discussion started by: tempestas
6 Replies

8. Shell Programming and Scripting

Assign result to variable

Hi friends, firstly, i can run following expression and i took 100 value. sqlplus -s username/password@TTTEST @umt.sql umt.sql exists "select t.deger from parametre t where". result of this query =100 i need to assign this value(100) to variable(for example x... (2 Replies)
Discussion started by: temhem
2 Replies

9. UNIX and Linux Applications

How to get a result of a cmd into variable?

Hi , I am trying following . I need to get a result of an autosys cmd into a unix variable. The autosys cmd is autostatus -G jpm_day_today Please help me in storing the value returned by this cmd into a unix variable. Appreciate your time to read this post. (1 Reply)
Discussion started by: manchau
1 Replies

10. Shell Programming and Scripting

output result (period -1)

hello, I have the following basic script which input the period, but I would like to output is period -1.. how? echo Please input period (yyyymm): read PERIOD OUTPUT=$PERIOD -1 echo " you request period -1 is $OUT" input 200705 output 200704 input 200701 output 200612 The above... (4 Replies)
Discussion started by: happyv
4 Replies
Login or Register to Ask a Question