Assign the return value of the SQL to a variable in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assign the return value of the SQL to a variable in UNIX
# 1  
Old 05-14-2015
Assign the return value of the SQL to a variable in UNIX

Hi

I am new to UNIX. I am trying the below and getting the error.

I am trying to assign the variable with the value of the query result. I want this value to use in the next steps.

Created UNIX file (Batch.sh) as below

#!/bin/ksh
sqlplus callidus/callidus4u@attstcal @Batch.sql

Created UNIX file (Batch.sql) as below

batchname = ~sqlplus -s callidus/callidus@attstcal <<EOC
select batchname from cs_table where rownum = 1 order by 1 desc;
EOF!
)
echo $batchname

I am getting the below error

"SP2-0734: unknown command beginning "batchname=" - rest of line ignored.

Can anyone please help.
# 2  
Old 05-14-2015
Please use code tags as required by forum rules!

I can't follow what you are doing there. Batch.sql seems to be run from within sqlplus, so it should not contain any shell commands/constructs, only sqlplus code. Plus, your here document seems broken (the delimiter does not match the word). Plus, there's an unmatched closing parethesis.
# 3  
Old 05-14-2015
If I update the files as below, will this resolve the issue.

Batch.sh:

#!/bin/ksh
sqlplus callidus/callidus4u@attstcal @Batch.sql
echo $batchname

Batch.sql:

batchname = ~sqlplus -s callidus/callidus@attstcal <<EOC
select batchname from cs_table where rownum = 1 order by 1 desc;
EOF~
)
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 Assign the Output of an SQL Query to a Variable?

Hi iam new to shell scripting how to declare variables as redshift query and I have to compare two counts by using if condition . ex:count=select count(*) from prd; select count(*) from prd; select count(*) from tag; can any one help me . Please use CODE tags when displaying... (1 Reply)
Discussion started by: sam526
1 Replies

2. Shell Programming and Scripting

How to assign value from isql to UNIX variable

I want output to be assigned to UNIX variables echo "Enter RRS ID: " read rrs isql -SPROD_DDS -USYBUSER -PSYBPASS -b -osfg.out << EOF use sip go set nocount on select issuerId, legalStructTxt, productName, issuerName from sf_product where rrsId = $rrs go EOF (1 Reply)
Discussion started by: JayDoshi
1 Replies

3. Shell Programming and Scripting

How to assign a shell variable to a NUMBER parameter in pl/sql?

I have the below script running for generating file from PL/SQL stored procedure. I need to declare a shell variable and then pass this to sqlplus command to pass the same as a INPUT parameter for the stored procedure. Please help to do this. #!/bin/sh minlimit=0 maxlimit=10 size=100 while... (0 Replies)
Discussion started by: vel4ever
0 Replies

4. 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

5. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

6. Shell Programming and Scripting

Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing... (1 Reply)
Discussion started by: MxC
1 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

To get value from oracle & assign it in UNIX variable

Hi Team, I need to get data from oracle table & need to assign that value to unix variable. I have serched the same in other threads. I found the following code. I have tried code to get the value from oracle. but it is not working. The error shows invalid identifier "NAM" & then list all... (5 Replies)
Discussion started by: Amit.Sagpariya
5 Replies

9. Shell Programming and Scripting

how to assign sql output data to shell script variable

Hi Guys ! I am new to unix and want to find out how we can make sql statement data to shell script variable? Any help/suggestion is greatly appreciated -Chandra (1 Reply)
Discussion started by: kattics
1 Replies

10. Shell Programming and Scripting

return variable from PL/SQL procedure to shell

Hi i'm calling a pl/sql procedure which is returning one variable. i'm trying to assing this value to variable in shell script the code i wrote is ** in shell script** var= 'sqlplus user/pass @ret.sql' echo $var ** and variable dum_var number exec rt_test(:DUM_VAR); exit; in... (4 Replies)
Discussion started by: ap_gore79
4 Replies
Login or Register to Ask a Question