How to split the sql output into two different variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split the sql output into two different variables
# 1  
Old 08-13-2012
How to split the sql output into two different variables

Hi,

How to set as variable from sql output.

Query:
Code:
 select aa.serial, ao.name from ann_amit aa JOIN ann_object ao on (aa.classid=ao.classid);

I got two values from aa.serial and ao.name, I wanna make two different variable for aa.serial and ao.name.

The value of aa.serial should be in one variable and
The value of ao.name should be in another variable

How i should do from shell script, please let me know

Last edited by Scott; 08-13-2012 at 06:39 AM.. Reason: Code tags
# 2  
Old 08-13-2012
Shell variablename can't include dot.
Code:
delim="|"    # col delim. in sql output
some_sql_command |  while IFS="$delim" read  aa_serial ao_name xstr
do
   echo "$aa_serial  - $ao_name"
done


Last edited by kshji; 08-13-2012 at 02:23 PM..
# 3  
Old 08-14-2012
You could try an array. This should work with bash; your shell might have another notation implemented:
Code:
aa_array=($(some_sql_command))

You get at the variables' contents like echo ${aa_array[0]} etc. Inserting # before the array name will yield the count of elements.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Need sql query to string split and normalize data

Hello gurus, I have data in one of the oracle tables as as below: Column 1 Column 2 1 NY,NJ,CA 2 US,UK, 3 AS,EU,NA fyi, Column 2 above has data delimited with a comma as shown. I need a sql query the produce the below output in two columns... (5 Replies)
Discussion started by: calredd
5 Replies

2. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

3. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

4. Web Development

split line based on delimeter SQL

I have a SQL query SELECT BLAH_ID, BLAH_CODE, DATEFORMAT(CALENDAR_DATE, 'MM-DD-YYYY') AS CALENDAR_DATE_STR, HOURS, 'N', FROM blah_tmp_tbl order by CALENDAR_DATE_STR,BLAH_ID,BLAH_CODE; OUTPUT TO 'MyExport.CSV' quote '' FORMAT ASCII; That gets me the below output; ... (2 Replies)
Discussion started by: ffdstanley
2 Replies

5. Shell Programming and Scripting

Split lines in a file and store them in variables

Hi, I have a file called files.txt which contains data like http://abc.xyz.com/ghi/klm/nop/qrs/tuv/wxyz/ There are multiple lines like the above in this file. In .sh script, I would like to read this file, split each line, and store the variable of "qrs" and "wxyz" in separate variables. ... (3 Replies)
Discussion started by: archana.n
3 Replies

6. Shell Programming and Scripting

sql output from multiple rows and columns as variables in a script

This is for an Oracle journal import. I was using a pl/sql package and oracle API's. Oracle added invoker rights to their API's and now my package won't run. I didn't want to use their API's anyway. The only reason i was using pl/sql and the API's (just a package) was to utilize a cursor. How... (2 Replies)
Discussion started by: lmu
2 Replies

7. Shell Programming and Scripting

Bash:How to split one string variable in two variables?

Hello, I have a paramter $param consisting just of two literals and want to split it into two parameters, so I can combine it to a new parameter <char1><string><char2>, but the following code didn't work: tmp_PARAM_1=cut -c1 $PARAM tmp_PARAM_2=cut -c2 $PARAM... (2 Replies)
Discussion started by: ABE2202
2 Replies

8. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

9. UNIX for Dummies Questions & Answers

split a single sql file into multiple files

Hi,I have a single sql file containing many create table ddl's.Example: CREATE TABLE sec_afs ( rpt_per_typ_c char(1) NOT NULL, rpt_per_typ_t varchar(20) NULL, LOCK ALLPAGES go EXEC sp_primarykey 'sec_afs', rpt_per_typ_c go GRANT SELECT ON sec_afs TO developer_read_only... (5 Replies)
Discussion started by: smarter_aries
5 Replies

10. Shell Programming and Scripting

KSH split string into variables

Hello, I am an intermediate scripter. I can usually find and adapt what I need by searching through previous postings, but I'm stumped. I have a string with the format "{Name1 Release1 Type1 Parent1} {Name2 Release2 Type2 Parent2}". It is being passed as an argument into a ksh script. I need to... (5 Replies)
Discussion started by: drd_2b
5 Replies
Login or Register to Ask a Question