Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / March 2005

Tip: Looking for answers? Try searching our database.

Filling ksh array with db2 returns..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cbielins@gmail.com - 17 Mar 2005 18:40 GMT
I'm trying to fill an array in korn shell with entries from a db2
query.  I've tried a straight `set -A <array_name>=`db2 -x <query>`` ,
but that doesn't work.

Can this sort of thing be done?

TIA,
Chris
lpedron@gmail.com - 18 Mar 2005 01:32 GMT
You could do several things short of an array.  For example:

for x in $( db2 -x "select...")
 do
    yada yada yada
 done

or

db2 -x "select  x, y, z from ..." | read x y z
 do
     yada yada yada
 done

But the problem with ksh arrays I've worked with is knowing how many
elements you'll have so I guess you could do something like this. (
forgive me because I syntax may be off because I'm using windows right
now and don't have access to ksh )

counter=1
for x in $(db2 -x "select y from...")
 do
    arr[${counter}]=$x
    counter=$(($counter+1))
 done

The problem with this approach would be only being able to select one
column with the query.

HTH
kenfar - 18 Mar 2005 02:45 GMT
> The problem with this approach would be only being able to select one
column with the query.

Yeah,  with multiple columns it can get easier to export to a delimited
file and read it back in and parse.  Alternatively, the inclusion of
literal columns like '|' in the output can help facilitate parsing.

And at this point running from within python/ruby/perl - where you can
more easily capture the output to an easily-manipulated array can help
as well.

ken
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.