Pass associative array contents from ksh to calling Ksh

I have following output from my plsql procedure :

name     values
-------------------------
log          abc_mmddyyyy.log
file          abc_mmddyyyy.txt
filepath   /root/abc/


I need to pass above values to ksh within which this procedure has been called and in return output them to different ksh.

My limitations are I cannot use nawk or perl. I can use awk and sed within ksh.
I am already using associative array inside plsql procedure where name is indexed.
I can also go without using an assiciative array inside plsql procedure by just having
a straight cursor to pull the name and values, but I need to get exactly the corresponding
values for the given names in the outer most(Parent) ksh.

Thanks in advance
aaba
aaba646Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MikeOM_DBAConnect With a Mentor Commented:
ok then just reverse the scripts like this:
(Note that I commented out the sqlplus crap and replaced by "echo")



#!/usr/bin/ksh
#
# Script: MainScript.sh
#
echo "Starting: $0 `date`"
#
# Set Array:
#
#
# Get array from MyScript.sh
#
set -A array `./MyScript.sh `
i=0
while [ i -lt ${#array[*]} ]
do
  echo "array $i: ${array[$i]}"
  ((i+=1))
done
############################


#!/usr/bin/ksh
#
# MyScript.sh - Generic script to provide values for array
#
export ORACLE_SID=ORCL
ORAENV_ASK=NO
#. /usr/local/bin/oraenv
##
## Get array from sqlplus
##
set -A array `
# Replace following "echo" commands with the sqlplus script:
# name, value
echo 'log abc_mmddyyyy.log'
echo 'file abc_mmddyyyy.txt'
echo 'filepath /root/abc/'
#
#sqlplus -s / <<EOSQL
#--
#-- Avoid headers and other stuff:
#--
#set pages 0 trims on term off
#--
#-- Here goes your query:
#--
#with tab as (
#select 'log' name, 'abc_mmddyyyy.log' value from dual union all
#select 'file', 'abc_mmddyyyy.txt' from dual union all
#select 'filepath', '/root/abc/' from dual)
#select * from tab;
#exit
#EOSQL
`
## Return array
echo "${array[*]}"
##

Open in new window

0
 
MikeOM_DBACommented:
Try something like this:

#!/usr/bin/ksh
export ORACLE_SID=SOACPROD
ORAENV_ASK=NO
. /usr/local/bin/oraenv
MyScript () {
set -A parm $1 $2 $3 $4 $5
for i in 0 1 2 3 4 5
do
  echo "parm $i: ${parm[$i]}"
done
}
##
## Get array from sqlplus
##
set -A array `
sqlplus -s / <<EOSQL
--
-- Avoid headers and other stuff:
--
set pages 0 trims on term off
--
-- Here goes your query:
--
with tab as (
select 'log' name, 'abc_mmddyyyy.log' value from dual union all
select 'file', 'abc_mmddyyyy.txt' from dual union all
select 'filepath', '/root/abc/' from dual)
select * from tab;
exit
EOSQL`
##
## Pass parameters to another script (Simulated by inline functiop)
##
MyScript "${array[*]}"

Open in new window

0
 
aaba646Author Commented:
Thanks Mike.
Is there a way that I can send all elements of array i.e array[*] dynamically to array parm with out hardcoding the number of arguments.
This is because my sql query might change at any time.

Thanks
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
MikeOM_DBACommented:
Try:


#...etc...
MyScript () {
set -A parm $*
#...etc...

Open in new window

0
 
aaba646Author Commented:
How can I assign the function MyScript array contents to the calling ksh array.
0
 
MikeOM_DBACommented:
Please clarify...
0
 
MikeOM_DBACommented:
OK try this (note the TWO scripts):


$ cat ./MainScript.sh
#!/usr/bin/ksh
#
# MainScript.sh
#
echo "Starting script: $0 `date`"
export ORACLE_SID=orcl
ORAENV_ASK=NO
. /usr/local/bin/oraenv
##
## Get array from sqlplus
##
set -A array `
sqlplus -s / <<EOSQL
--
-- Avoid headers and other stuff:
--
set pages 0 trims on term off
--
-- Here goes your query:
--
with tab as (
select 'log' name, 'abc_mmddyyyy.log' value from dual union all
select 'file', 'abc_mmddyyyy.txt' from dual union all
select 'filepath', '/root/abc/' from dual)
select * from tab;
exit
EOSQL`
##
## Pass parameters to another script (MyScript.sh)
##
./MyScript.sh ${array[*]}
exit


$ cat MyScript.sh
#!/usr/bin/ksh
#
# MyScript.sh Script...
#
echo "Starting script: $0 `date`"
echo "------------------------------------------------------------"
set -A parm $*
i=0
while test i -le $#
do
  echo "parm $i: ${parm[$i]}"
  ((i+=1))
done
exit

Open in new window

0
 
aaba646Author Commented:
Thanks for all the above more detailed example but my requirement is the other way round.
I want the SQL to be part of more generic ksh and when ever called from other ksh, the generic ksh array elements should be available to the calling ksh. More specifically for above example, Myscript.ksh should return the sql query ouput to Mainscript.ksh as array, when Myscript.ksh is called from Mainscript.ksh. I tried with exporting all array elements inside the loop but I was not successful.

I hope I have not missed any details.

Thanks
0
 
aaba646Author Commented:
It woks Perfect.
Thanks Mike.
0
All Courses

From novice to tech pro — start learning today.