The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
How to: Parse text string into variables using Korn shell shew01 Shell Programming and Scripting 7 05-23-2008 10:01 AM
Accessing Shell Variables in awk or sed nasersh Shell Programming and Scripting 3 05-05-2008 07:44 AM
accessing variables declared in another perl script gurukottur Shell Programming and Scripting 3 11-09-2006 09:22 PM
Variables Naming in Korn Shell aldowsary Shell Programming and Scripting 1 03-19-2006 12:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-01-2007
bright_future bright_future is offline
Registered User
  
 

Join Date: Nov 2007
Location: India
Posts: 3
Smile Accessing PL/SQL OUT variables in Korn Shell Script

Hello All,

I was just wondering if there is any direct way to access PL/SQL OUT variables from Korn Shell Script.

I could already figure out how to return a single value back from PL/SQL to Shell Script (using bind variable).
But, what if we want to return multiple values?

One option I found in some previous posts, is to print all the OUT variables (using DBMS_OUTPUT.PUT_LINE feature) to some log file and then use egrep, sed or awk to find those variables.
But, that's an indirect way (a work-around) I would say.
Isn't there any direct solution available with Unix?

Please help me.

Quick responses would be appreciated.

  #2 (permalink)  
Old 11-01-2007
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,726
Ways to get variable values out of PL/SQL:
1. call dbms_output, search log file or use grep in the script to find values
2. call utl_file, write values -> read values from file in script
3. make pl/sql call a subprocess, then set into envrionment variable probably an array
Code:
#!/bin/ksh
run_sql()
{
     sqlplus -s user/pswd <<EOF
     DECLARE
             ........
     BEGIN
             .......
     END;
     /
EOF     
}
set -A arr $( run_sql )
  #3 (permalink)  
Old 11-02-2007
bright_future bright_future is offline
Registered User
  
 

Join Date: Nov 2007
Location: India
Posts: 3
Exclamation Looking for better resolution

Many thanks for your quick reply.

However, the solutions do not solve the problem I am facing.

First 2 solutions are indirect ways, like I mentioned in my original post.

The 3rd solution is good infact, but I forgot to mention in my original post that my PL/SQL block prints many messages using dbms_output feature.
Hence, if I store everything in "arr" variable you suggested, than I will have to use grep again, to find out the variables I need.

If there is no other direct way to output PL/SQL variables to Shell script, then I may go with the 3rd solution (as the last choice).

Anyway, thanks again!
  #4 (permalink)  
Old 11-28-2008
kiranlalka kiranlalka is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 11
Quote:
Originally Posted by bright_future View Post
Many thanks for your quick reply.

However, the solutions do not solve the problem I am facing.

First 2 solutions are indirect ways, like I mentioned in my original post.

The 3rd solution is good infact, but I forgot to mention in my original post that my PL/SQL block prints many messages using dbms_output feature.
Hence, if I store everything in "arr" variable you suggested, than I will have to use grep again, to find out the variables I need.

If there is no other direct way to output PL/SQL variables to Shell script, then I may go with the 3rd solution (as the last choice).

Anyway, thanks again!
Dude,

have you got any better way.... if yes can share the code...

even if you used the above one can you share the code
  #5 (permalink)  
Old 12-02-2008
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
Is this the sort of thing you are looking for?

Code:
$ cat test_get_oracle_vars.ksh
#!/bin/ksh
run_sql()
{
  $ORACLE_HOME/bin/sqlplus -S <<EOF
  user/psw
  SET PAGESIZE 0;
  SET FEEDBACK OFF;
  SET SERVEROUT ON;
  VAR major NUMBER;
  VAR minor NUMBER;
  EXEC DBMS_PROFILER.GET_VERSION (:major, :minor);
  PRINT major;
  PRINT minor;
EXIT;
EOF
}


set -A ARRAY $(run_sql)
ARRAYCOUNT=${#ARRAY[*]}
ARRAYIDX=0

while (( $ARRAYIDX < $ARRAYCOUNT ))
do
 echo  "ARRAY[$ARRAYIDX]=(${ARRAY[ARRAYIDX]})"
 ARRAYIDX=$(($ARRAYIDX+1))
done

exit 0

$ ./test_get_oracle_vars.ksh
ARRAY[0]=(2)
ARRAY[1]=(0)
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0