- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Returning result of an Oracle stored procedure to ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 05:37 AM
тАО07-31-2002 05:37 AM
What I would like to do is be able to return a value from the stored procedure back to the shell script. I could then use that value to control the rest of the program execution (i.e fire off an error e-mail, or keep going with the processing). I am thinking that I should be able to do this, but just don't know quite how...
I am limited to regular shell script commands -no perl, c, etc...
Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 05:41 AM
тАО07-31-2002 05:41 AM
Re: Returning result of an Oracle stored procedure to a shell script
echo $? display the return status of the last excuted command. 0 means OK and 1 means NOTOK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 05:49 AM
тАО07-31-2002 05:49 AM
Re: Returning result of an Oracle stored procedure to a shell script
Thanks for the quick response. As far as the return status of the last command - that won't work b/c the comamnd is the call to sqlplus - which will be sucsessful either way.
You also mention writing the status to a separate file. I have considered this one - my problem is that yu can't just spool from a stored procedure. We have not used the built-in utlfile procedures yet. Is there an easy way to "write out" this status from within the stored procedure?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 05:50 AM
тАО07-31-2002 05:50 AM
Re: Returning result of an Oracle stored procedure to a shell script
1) Use the PID of your current shell to build a
known temp filename. e.g. /var/tmp/X${$}_1.out
2) Send that filename in to a second script that builds SQL scripts 'on the fly' and instructs SQL to list results in the temp file. e.g. Line1 might contain the results of the first stored procedure. You then call sqlplus from this shell script.
3) You should then be able to read the temp file in your parent shell. When finished, remove the temp file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 06:07 AM
тАО07-31-2002 06:07 AM
Re: Returning result of an Oracle stored procedure to a shell script
This is pretty much the only option I could think of (well, not the whole dynamic filename thing and all, but the basic concept). I can go that way, but, before I do - just to verify - is there really no way to get an actual returned value from the stored procedure?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-31-2002 06:01 PM
тАО07-31-2002 06:01 PM
Re: Returning result of an Oracle stored procedure to a shell script
I have personally been finding that doing major coding portions using dbms_job is faster and easier, and keeps you from using shell scripts where possible.
If you would like some help outside of the forum, write back and I may be able to give you some ideas.
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 02:27 AM
тАО08-01-2002 02:27 AM
Re: Returning result of an Oracle stored procedure to a shell script
Script:
#!/bin/sh
VALUE=`sqlplus -silent scott/tiger@pf7a <
select count(1) from user_objects;
exit;
END`
if [ -z "$VALUE" ]; then
echo "No rows returned from database"
exit 0
else
echo $VALUE
fi
Output :
v701-DEV(sjc)$ t
443
This came from metalink. Search on Subject: Passing values to OS shell scripts.
HTH
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 05:45 AM
тАО08-01-2002 05:45 AM
Re: Returning result of an Oracle stored procedure to a shell script
Simon - I'll try your suggestion out - I might be able to get that to do what I need instead of actually passing a value back.
I'll assign points tomorrow after I try them out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 05:56 AM
тАО08-01-2002 05:56 AM
Re: Returning result of an Oracle stored procedure to a shell script
well the easiest way inside a database to "log" is to log to a table.
You could either log by direct call or can do it by using a trigger.
After a crash you just select the logtable and see how far it got.
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 08:48 AM
тАО08-01-2002 08:48 AM
Re: Returning result of an Oracle stored procedure to a shell script
First, use the WHENEVER OSERROR/SQLERRROR comands to set the return code of the SQL*Plus script to a value you can trap:
WHENEVER OSERROR EXIT 2;
WHENEVER SQLERROR EXIT 3;
Then use a bind variable in SQL*Plus that you can set from inside a PL/SQL procedure:
VARIABLE return_val number;
Inside your procedure, you set this value by prepending a colon:
IF ts_count != 0 THEN
:return_val := 2;
END IF;
Finally, as the last line of your script, use the SQL*Plus exit command, returning the bind variable as the exit status.
exit return_val;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 01:41 AM
тАО08-02-2002 01:41 AM
Solution#!/bin/sh
SHELL_VAR=`sqlplus -s un/pw <
var plusvar varchar2(100)
exec stored_proc_name (:plusvar)
print plusvar
EOF`
echo ${SHELL_VAR}
# or process SHELL_VAR according to your needs
This way, you won't have to rework your stored proc to include dbms_output statements, you can use it just as it is. Also, you can return character values - SQL*Plus exit restricts you to numeric values only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-02-2002 07:50 AM
тАО08-02-2002 07:50 AM
Re: Returning result of an Oracle stored procedure to a shell script
Simon - yours did work, and got me part way there. It would have been an okay workaround if I needed to.
Mark - yours also would have worked if I could not get exactly what I wanted (returning different text statuses).
Dave - Exactly what I needed.
For future reference, here is what I ended up with:
the shell script:
VALUE=`$ORACLE_HOME/bin/sqlplus -s user/pass @sqlscript`
if [ "$VALUE" = 'ERROR TYPE 1' ];
then
code to process here;
else
code to process here;
fi
the sql script:
set pagesize 0
set feedback off
set verify off
set heading off
set echo off
var out_status varchar2(30)
exec sp_tester(:out_status);
print out_status
exit;
the stored procedure:
procedure sp_tester (out_status out varchar2) is
begin
select 'ERROR TYPE 1' from dual;
end;
Thanks again everyone.