How to access outparameter of a Procedure called inside a shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to access outparameter of a Procedure called inside a shell script?
# 1  
Old 04-02-2012
How to access outparameter of a Procedure called inside a shell script?

Hi

I am calling a PLSQL procedure inside a shell scipt.
How to access out paramters of this procedure inside the mail shell script.

I am using below peiece of code.

Code:
echo " inside PKG validation"
       `sqlplus -s login/password@database <<EOF
          set heading off
          set feedback off
          set pagesize 0
          set linesize 32767



           VARIABLE l_out_put      VARCHAR2(1000)
           VARIABLE l_change_flag  VARCHAR2(2)
             exec xxat_sox_proc('$file_name',:l_out_put,:l_change_flag);
          print l_out_put
          print l_change_flag
       exit
       EOF`
        if [ $l_change_flag = "Y" ]
        then
echo " after if"
        echo "$l_out_put" >> SOX_`date +'%Y%m%d'`
        fi

Here my IF condition is failing as unix is unable to recognise it.

Appreciate your quick response

Last edited by methyl; 04-03-2012 at 08:07 AM.. Reason: code tags ; remove server login details
# 2  
Old 04-02-2012
Your SQL session will presumeable display the correct results to you, so what you need to do with the shell script is to read them in.

Are you expecting a single line with two values from your SQL or two lines?

If it is the latter, then after you EOF, try inserting the following:-
Code:
read l_out_put
read l_change_flag

This may hang if your shell decides it really wants to display the answers and then read input from the keyboard. Perhaps you need to change then end of your SQL block to read:-
Code:
   print l_out_put
          print l_change_flag
       exit
       EOF`|while read l_out_put
                do
                    read l_change_flag
                done
        if [ $l_change_flag .........

Does that steer you towards a solution?

If not, can you run the SQL bit and paste the output from that and I'm sure someone will get it sorted.




I hope that this helps,
Robin
Liverpool/Blackburn
UK
# 3  
Old 04-02-2012
Here's an example I did once to illustrate reading output from SQL/Plus and putting the data returned into shell variables. Maybe the general framework here will help you. This is ksh93 on Solaris:
Code:
#!/usr/dt/bin/dtksh
unset version
unset status

( sqlplus -s login/password@database <<EOF
  set heading off;
  select 'version='||'1.2' from dual;
  select 'status='||'UP' from dual;
  exit;
EOF
)|
while read line
do
 if [[ -n $line ]]
   then eval $line
 fi
done

print "Version: $version"
print "Status: $status"

P.S. You best change your apps password ASAP!!!

Last edited by gary_w; 04-02-2012 at 02:01 PM..
This User Gave Thanks to gary_w For This Post:
# 4  
Old 04-02-2012
Code:
       EOF`

This line must not be indented or it will not work and all the remaining lines in the script will be presented to sqlplus.
Try this:
Code:
EOF`

# 5  
Old 04-03-2012
If indenting makes the code more readable, I have found that using a TAB characters to indent is acceptable to ksh, however spaces are a definite no-no.



Robin
Liverpool/Blackburn
UK
# 6  
Old 04-03-2012
If you have <<-EOF instead of <<EOF the terminator EOF of the Here Document can be indented with tabs.

Last edited by methyl; 04-03-2012 at 08:04 AM.. Reason: qualify "with tabs"
# 7  
Old 04-03-2012
Quote:
Originally Posted by rbatte1
If indenting makes the code more readable, I have found that using a TAB characters to indent is acceptable to ksh, however spaces are a definite no-no.
Tabs or spaces makes no difference with <<, both will cause the terminator to be ignored.

If you use <<-, you can use tabs (but not spaces).

EDIT: As methyl said. (*curses lack of delete button* Smilie)

EDIT2: And apparently <<# allows both (on ksh93, at least).

Last edited by CarloM; 04-03-2012 at 07:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Ceiling Light - The Forgotten Element One of the highest details concerning using an LED ceiling panel essentially offer a fantastic dance floor which definitely makes the customers dance right away.They are a quite low cost method of something like a lighting solution, simple collection up,... (1 Reply)
Discussion started by: harveyclayton
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass values to a script called from within another script in shell?

Need ideas on how to achieve the below. We have a script say "profile.sh" which internally calls another existing script called "name.sh" which prompts for the name and age of a person upon execution. When i run profile.sh how can i populate a pre-defined value from another file and pass that... (1 Reply)
Discussion started by: sankasu
1 Replies

3. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

4. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. UNIX for Dummies Questions & Answers

Interpreting Shell Script errors when called from CRON

Hi All, I am calling a series of shell scripts via CRON so everything is running as root. However, in my error log file I am seeing the following errors. Please can anyone offer any advise as to the possible causes and solution to prevent the errors from appearing. The Error 1227 seems to... (2 Replies)
Discussion started by: daveu7
2 Replies

6. UNIX for Advanced & Expert Users

Why only partiial shell script got executed when called in Java

I'm trying to call shell scripts from Java for DB operations. Using a very simple test, for some reason, one line of (ALTER TABLE) in the shell simply won't be executed while the exit value from the call is "0" (valid exit). When I run the script directly in Unix, it gets executed perfectly fine!!... (4 Replies)
Discussion started by: zmwang
4 Replies

7. UNIX for Dummies Questions & Answers

How to retrieve the value of variable in shell script which is called by crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (4 Replies)
Discussion started by: jadoo_c2
4 Replies

8. Shell Programming and Scripting

how to access variables in a config file inside a shell script

I'm writing a shell script. I want to put the variables in a separate config files and use those inside my script. e.g. the config file (temp.conf)will have the values like mapping=123 file_name=xyz.txt I want to access these variables in temp.conf(i.e. mapping and file_name) from inside the... (7 Replies)
Discussion started by: badrimohanty
7 Replies

9. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question