Accessing PL/SQL OUT variables in Korn Shell Script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Accessing PL/SQL OUT variables in Korn Shell Script
# 1  
Old 11-01-2007
Bug 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  
Old 11-01-2007
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  
Old 11-02-2007
Error 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  
Old 11-28-2008
Quote:
Originally Posted by bright_future
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  
Old 12-02-2008
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)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help: Shell script to call sql session with variables stored in .txt file

Hi, I need help in writing a shell script which can read data from a text file (Cancel_ID.txt) and then calls sqlplus session (Cancel.sql) with the first line parameter of the text file ("0322600453") till all rows are not completed. ... (4 Replies)
Discussion started by: Khan28
4 Replies

2. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies

3. Programming

create a spool file based on values passed from korn shell to sql script

this is my issue. 4 parameters are passed from korn shell to sql script. parameter_1= varchar2 datatype or no value entered my user. parameter_2= number datatype or no value entered my user. parameter_3= number datatype or no value entered my user. parameter_4= number datatype or no... (5 Replies)
Discussion started by: megha2525
5 Replies

4. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

5. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

Hi All, I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh. For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access... (2 Replies)
Discussion started by: rsendhilmani
2 Replies

6. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

7. Shell Programming and Scripting

Problem in accessing variables outside shell

Hi, I have a shell script wherein i am doing some file operations and storing the data in some variables. I am exporting these variables as i need to use them outside shell. Then within the shell i am launching GDB session hoping that i will be able to access the exported variables in the GDB... (2 Replies)
Discussion started by: jsantosh
2 Replies

8. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

9. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

10. Shell Programming and Scripting

Shell script for accessing a file in the network drive and invoking oracle sql loader

Hi, Please let me know if anybody is having a solution handy for the below tasks... It would be helpful if somebody can resolve my query. I am new to unix and oracle environment and looking for some online reference for completing a task. Task: Check if the network drive exists Check... (0 Replies)
Discussion started by: sayydevara
0 Replies
Login or Register to Ask a Question