Oracle output to an array variable in script


 
Thread Tools Search this Thread
Operating Systems AIX Oracle output to an array variable in script
# 1  
Old 11-25-2013
Oracle output to an array variable in script

Hi- I am returning output of an query into a array variable in my shell script.

Code:
set -A DATE_RANGE `sqlplus -s **/**@** << EOF
set termout off
set echo off
set serveroutput off
set pagesize 0
set linesize 500
set heading off
set verify off
set feedback off
select (to_char(MAX_LOAD_TRAN_DT,'YYYY-MM-DD HH:MM:SS')||','||BACK_UPDT_DAY_CNT) as DATE_RANGE from
TABLE A,TABLE B
WHERE TRGT_TBL_NM IN ('**')
AND A.SRC_TBL_INFO_KEY=B.SRC_TBL_INFO_KEY;
quit;
EOF`
 
The output of the query is -
 
2013-09-21 12:09:00,5 
2013-09-19 22:36:00,7
2013-09-20 06:28:00,1 
 
So, the output I wanted to see in the array variables is-
 
${DATE_RANGE[0]} - 2013-09-21 12:09:00,5 
${DATE_RANGE[1]} - 2013-09-19 22:36:00,7 
${DATE_RANGE[2]} - 2013-09-20 06:28:00,1
 
But the output am getting is-
 
 
${DATE_RANGE[0]} - 2013-09-21 
${DATE_RANGE[1]} - 12:09:00,5 
${DATE_RANGE[2]} - 2013-09-19 
${DATE_RANGE[3]} -  22:36:00,7


It is treating space as record delimiter instead of Unix new line. How to avoid this? How to define an record delimiter to an Array variable?
# 2  
Old 11-25-2013
The IFS variable controls what characters the shell splits upon. By default it is all whitespace.

Code:
OLDIFS="$IFS"
IFS="
"

# code that populates the array

IFS="$OLDIFS" # Restore it, since lots of things depend on default behavior here

# You can now use your array as expected


Last edited by Corona688; 11-25-2013 at 12:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies

2. Shell Programming and Scripting

Storing the Linux command output to an array in perl script

Hi I am trying to store the output of a command into an array in perl script. I am able to store but the problem is i am unable to print the array line with one line space. i mean i inserted the \n in loop ...but not getting the result. I have written like this #!/usr/bin/perl @a =... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

3. Shell Programming and Scripting

Script to store the variable in a table or array.

Hi, I have few variable say 10 ex:- l_pc_291334_01_0_01_00.cmp l_pc_441133_50_0_02_00.cmp l_pc_441133_55_0_02_00.cmp Each variable value is coming via loop on a table. I want to create a script that stores these value to a table or array ( But one by one not all at one time as... (4 Replies)
Discussion started by: amitkumar.b2
4 Replies

4. UNIX for Dummies Questions & Answers

SQL loader script - ORACLE environmental variable

I am new in unix.. I am running a sql loader script where I have to specify the data file path but the file name contains spaces in it so giving error multiple arguments I have tried it with "" and '' but does n't work the command is : $ORACLE_HOME/bin/sqlldr... (1 Reply)
Discussion started by: Sandip Dey
1 Replies

5. Shell Programming and Scripting

System Output in to an Array or variable

hey guys in only new to scripting as such, but i have a problem. i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output. this this what im doing: -bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc= # base... (1 Reply)
Discussion started by: jmorey
1 Replies

6. Shell Programming and Scripting

Assign dscl output to variable as an array

Greetings folks, I am trying to assign the output of a dscl command (contains name<spaces>id) to a variable as an array. Currently I am piping the output into a tmp file, then reading the tmp file into an array, then parsing the array. I would like to bypass creating the tmp file portion of... (6 Replies)
Discussion started by: macnetdaemon
6 Replies

7. Shell Programming and Scripting

accessing a variable or array of one script in another

hi all, i've a requirement like this. i want to access the contents of an array declared in one script,which is a bash script, to a second script which is a perl script. actually i want a sort of global variable which can be accessed in other script like environmen variables and also i can... (3 Replies)
Discussion started by: tprayush
3 Replies

8. Shell Programming and Scripting

Perl script variable passed to Oracle query

Hi All, I pass a Perl script variable, whch is passed to a query to be prepared. But the problem is I have special character like '&' in this variable which are handled in a special way by the Oracle query parser. How do I get over this? my $cust_name='A&B'; my $sql="Select cust_short_name... (1 Reply)
Discussion started by: rahulrathod
1 Replies

9. Shell Programming and Scripting

how to return an array of elements from oracle to shell script

Hi all, I have a interresting problem. My application is as follows: From a shell script i will conn to a oracle database and fetch few rows using a select statement. Then i want to sort these rows and return a column (collection of values of a column from the selected results) as array... (3 Replies)
Discussion started by: satyakiran
3 Replies

10. UNIX for Dummies Questions & Answers

How to pass a oracle variable back to the shell script

Hi, I am calling an oracle function that returns a number (either 0 or 2), how do I pass that pass to the wrapping shell script as I would like to do other things based on the value returned by the oracle function. Your help will be appreciated. -------------------------- sqlplus / <<... (3 Replies)
Discussion started by: Jtrinh
3 Replies
Login or Register to Ask a Question