Solved

Getting multiple output values back from SqlPlus call

Posted on 2003-11-21
7
558 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
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 122
Looking for a specific application/software 2 92
sum67 challenge 35 89
Line meaning 9 77
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now