Assigning multiple column's value from Oracle query to multiple variables in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning multiple column's value from Oracle query to multiple variables in UNIX
# 1  
Old 01-12-2016
Code Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All,

I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row).

I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I could use 'cut' and assign values to all the required 10 variables from V.

But the thing is some of the the columns have special character and it is kind of hard for me to cut out the required details. Sometimes the delimiter(;)itself is present in column value. Also the code is very lengthy.

Is there a better way to assign multiple column values from query to unix variables.?

Also when i read '-e' from query and pass it unix varaible it becomes '?e'. Is there anyway we could solve this.

Thanks.

Last edited by Don Cragun; 01-12-2016 at 05:33 PM.. Reason: Add ICODE tags to avoid smiley expansion.
# 2  
Old 01-12-2016
Code:
$ echo ${.sh.version}
Version M 93t+ 2009-05-01
$ s="a b c d e f g h i j"
$ set -- $s
$ echo $1
a
$ echo $3
c
$ echo $5
e

# 3  
Old 01-12-2016
Why would you try using read -e to process output from a database query? The read -e option is only intended to process input from a terminal. Try:
Code:
IFS=';' read -r v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 <<EOF
$V
EOF

# 4  
Old 01-13-2016
You need to make sure that the delimiter is NOT part of the data; I remember faintly ORACLE allows for that (set COLSEP ...). Then, you don't need a shell variable to hold the selection's interim result, try
Code:
IFS='X' read -r v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 <<EOF
$(sql ... )
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. UNIX for Dummies Questions & Answers

UNIX multiple column sort

Hi, I have a text file that has data like this chr1 156106712 156106819 LMNA 8 + 1 147 chr1 156106712 156106819 LMNA 8 + 2 147 chr1 156106712 156106819 LMNA 8 + 3 148 chr1 ... (4 Replies)
Discussion started by: mitt
4 Replies

3. Shell Programming and Scripting

Assigning multiple variables in ksh script

Is it possible to have a user input multiple words in one line and have the script assign each word a variable? I'm stuck please assist. Example using "BILL JOHN SARA JILL" as what the user could type: printf "Enter account names: " BILL JOHN SARA JILL read input (9 Replies)
Discussion started by: seekryts15
9 Replies

4. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

5. Shell Programming and Scripting

Multiple Query Results to Variables

Hello, I am very new to shell scripting and I am not sure of how best to handle the following scenario. I need to query a list of values from a table. I need to store those results and use them to selectively delete values in yet another table in a separate database. I do know how to store the... (3 Replies)
Discussion started by: flowervz
3 Replies

6. Web Development

mysql query for multiple columns from multiple tables in a DB

Say I have two tables like below.. status HId sName dName StartTime EndTime 1 E E 9:10 10:10 2 E F 9:15 10:15 3 G H 9:17 10:00 logic Id devName capacity free Line 1 E 123 34 1 2 E 345 ... (3 Replies)
Discussion started by: ilan
3 Replies

7. Shell Programming and Scripting

Filtering Multiple variables from a single column

Hi, I am currently filtering a file, "BUILD_TIMES", that has multiple column of information in it. An example of the data is as follows; Fri Nov 5 15:31:33 2010 00:28:17 R7_BCGNOFJ_70.68 Fri Nov 5 20:57:41 2010 00:07:21 R7_ADJCEL_80.6 Wed Nov 10 17:33:21 2010 00:01:13 R7_BCTTEST3_80.1X... (7 Replies)
Discussion started by: crunchie
7 Replies

8. Shell Programming and Scripting

Oracle Query results to be stored in variables using unix

I want to store the sql query output into a variable #!/bin/ksh ORACLE_SID=DB01; export ORACLE_SID; export FILE_PATH=/home/asg/Tmp # Order Checking echo " removing old files " rm $FILE_PATH/Malformed_Order.txt echo " Enter the Malformed Order ....!" read orders echo "Regrade... (5 Replies)
Discussion started by: Nareshp
5 Replies

9. Shell Programming and Scripting

put value of multiple sql statements into unix variables

i want to use multple sql count statements and store these count values in unix variable but in one connection only i.e. in only 1 time database should be hit ,which is the main requirement. (1 Reply)
Discussion started by: sw@pnil
1 Replies

10. Shell Programming and Scripting

How to execute multiple(batch) oracle script in unix mechine

Hi All, How to run multiple oracle script in unix at-a-time.I appriciate if any send the script for me. Regards, Ravi kumar.Gongati (2 Replies)
Discussion started by: ravi gongati
2 Replies
Login or Register to Ask a Question