Solved

Getting multiple output values back from SqlPlus call

Posted on 2003-11-21
7
563 Views
Last Modified: 2013-12-26
I am using Korn Shell scriptiing. Can somebody show me the syntax to return multiple parameters from a call to SqlPlus? Let's say I execute a function in SqlPlus and would like to return more than 1 parameters. How do I do it? Here is an example syntax to return 1 output parameter.

vcSqlResults=`sqlplus @MyProc.sql'

but vcSqlResults would have only 1 parameter and I want more than 1.

Thank you very much.
0
Comment
Question by:mfarid2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9801952
example, only this time we will read multiple values from SQL*Plus into shell variables.
      sqlplus  -s /nolog |&     # Open a pipe to SQL*Plus
      
      print -p -- 'connect user/password@instance'
      print -p -- 'set feed off pause off pages 0 head off veri off line 500'
      print -p -- 'set term off time off'
      print -p -- "set sqlprompt ''"
      
      print -p -- "select sysdate from dual;"
      read  -p SYSDATE
      
      print -p -- "select user from dual;"
      read  -p USER
      
      print -p -- "select global_name from global_name;"
      read  -p GLOBAL_NAME
      
      print -p -- exit
      
      echo SYSDATE:     $SYSDATE
      echo USER:        $USER
      echo GLOBAL_NAME: $GLOBAL_NAME

Note: In all these examples we use the -s or -silent option to suppress SQL*Plus banners. The /nolog option indicates that the script will login to the database. This prevents Unix from displaying your userid and password in the Unix process list (ps -ef).

http://www.orafaq.com/faqunix.htm
0
 

Author Comment

by:mfarid2
ID: 9802025
Thank you shivsa for your response. Unfortunately, it doesn't answer my question. My Sql Plus call to a function will multiple parameters. So your method simply will not work. You can have arrays in Korn Shell. We need some way of retrieving these parameters in either in array or some other way.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9802281
> vcSqlResults=`sqlplus @MyProc.sql'
is wrong syntax, should be:
  vcSqlResults=`sqlplus @MyProc.sql`

Also, could please give an example what you receive in $vcSqlResults
and what you expect
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:HamdyHassan
ID: 9802504
I am also interested to see the source of this MyProc.sql or at least the part that returns more than one value

One idea,
if your final select will be something like
     select f1, f2 , f3 from table

you could do
 select f1 +  "|" +   f2 +  "|" +  f3 from table   ( Not sure about syntax to concatenate in oracle )

this select will return one value, then at Unix you could split it as you want

cut -f1 -d"|"
cut -f2 -d"|"
etc...



   
0
 
LVL 7

Accepted Solution

by:
glassd earned 125 total points
ID: 9802710
One way:

sqlplus @MyProc.sql | read var1 var2 var3

echo $var1
echo $var2
echo $var3


Or:

set `sqlplus @MyProc.sql`

while [[ $# -gt 0 ]]
do
   echo $1
   shift
done
0
 
LVL 18

Expert Comment

by:liddler
ID: 10191772
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by glassd

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 96
Add content to output file 4 71
no14 challenge 14 73
Change to event 1 129
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question