The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pass variable from awk to shell script user_prady Shell Programming and Scripting 3 04-17-2008 06:43 AM
Is it possible to pass variable from awk to shell back unishiva Shell Programming and Scripting 12 03-03-2008 01:44 PM
Is it possible to pass variable from awk to shell script user_prady Shell Programming and Scripting 3 12-18-2007 10:06 AM
How to Pass variable to shell Script sam70 UNIX for Dummies Questions & Answers 5 08-23-2005 08:27 PM
How to pass a oracle variable back to the shell script Jtrinh UNIX for Dummies Questions & Answers 3 07-11-2005 03:07 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 08-01-2008
ttunell ttunell is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 4
How to pass the result of an anonymous pl/sql block back to a shell script variable

I have the following function declared in my shell script:

write_to_stage_tables()
{
l_result=`sqlplus -s ${l_user_pwd} <<eof
whenever oserror exit sql.oscode rollback
whenever sqlerror exit sql.sqlcode rollback

set serverout on size 1000000;
set head off feedback off pages 0;
declare

l_ret_status varchar2(10);
l_ret_msg varchar2(2000);
l_event_text varchar2(2000);
l_event_details varchar2(2000);

e_write_to_stage exception;

begin

l_event_text := 'Call to xxwsh_ship_confirm.load_invoice_stg_tables';

xxwsh_ship_confirm.load_invoice_stg_tables
(
p_ret_status => l_ret_status
,p_ret_msg => l_ret_msg
);

if l_ret_status != 'S' then

l_event_details := l_ret_msg;
raise e_write_to_stage;

end if;

commit;

exception
when e_write_to_stage
then

rollback;

xxexcpt_log_pub.initialize ('XXWSH_INVOICE_FILE_LOAD');
xxexcpt_log_pub.write_exception
(
pi_exception_type => xxexcpt_log_pub.g_excpt_type_user_defined
,pi_exception_name => 'E_WRITE_TO_STAGE'
,pi_parameters => null
,pi_location => l_event_text
,pi_location_details => l_event_details
,pi_package_name => 'XXWSH_INVOICE_FILE_LOAD'
,pi_procedure_name => 'WRITE_TO_STAGE_TABLES'
,pi_table_name => null
,pi_column_name => null
,pi_column_value => null
,pi_error_message => 'See reqest log output for request $4'
);

when others
then

rollback;

l_event_details := sqlerrm;

xxexcpt_log_pub.initialize ('XXWSH_INVOICE_FILE_LOAD');
xxexcpt_log_pub.write_exception
(
pi_exception_type => xxexcpt_log_pub.g_excpt_type_system_explicit
,pi_exception_name => 'OTHERS'
,pi_parameters => null
,pi_location => l_event_text
,pi_location_details => l_event_details
,pi_package_name => 'XXWSH_INVOICE_FILE_LOAD'
,pi_procedure_name => 'WRITE_TO_STAGE_TABLES'
,pi_table_name => null
,pi_column_name => null
,pi_column_value => null
,pi_error_message => l_event_details
);

end;

/
commit;
exit
eof`

echo ${l_result}
}

In my shell script I call it by the following:

l_status=`write_to_stage_tables`

What I need to populate into the l_status variable is the value of l_result from my function. What am I missing here?

Thanks in adavance!
  #2 (permalink)  
Old 08-01-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
How does it not work? The use of backticks within backticks is redundant, though; perhaps you would get better results if you took out the backticks from inside write_to_stage_tables and simply let the backticks from the call of the function capture the output from SQL. (Using echo, especially without proper quoting, might lose significant whitespace from the string you are echoing.)
  #3 (permalink)  
Old 08-01-2008
ttunell ttunell is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 4
How I got it to work....

I was able to get the value passed back out of my pl/sql block by returning the wanted value using dbms_output.put_line.

write_to_stage_tables()
{
l_return=`sqlplus -s ${l_user_pwd} <<eof
whenever oserror exit sql.oscode rollback
whenever sqlerror exit sql.sqlcode rollback

set serverout on size 1000000;
set head off feedback off pages 0;
declare

l_ret_status varchar2(10);
l_ret_msg varchar2(2000);
l_event_text varchar2(2000);
l_event_details varchar2(2000);

e_write_to_stage exception;

begin

l_event_text := 'Call to xxwsh_ship_confirm.load_invoice_stg_tables';

xxwsh_ship_confirm.load_invoice_stg_tables
(
p_ret_status => l_ret_status
,p_ret_msg => l_ret_msg
);

if l_ret_status != 'S' then

l_event_details := l_ret_msg;
raise e_write_to_stage;

end if;

commit;

dbms_output.put_line(l_ret_status);

exception
when e_write_to_stage
then

rollback;

xxexcpt_log_pub.initialize ('XXWSH_INVOICE_FILE_LOAD');
xxexcpt_log_pub.write_exception
(
pi_exception_type => xxexcpt_log_pub.g_excpt_type_user_defined
,pi_exception_name => 'E_WRITE_TO_STAGE'
,pi_parameters => null
,pi_location => l_event_text
,pi_location_details => l_event_details
,pi_package_name => 'XXWSH_INVOICE_FILE_LOAD'
,pi_procedure_name => 'WRITE_TO_STAGE_TABLES'
,pi_table_name => null
,pi_column_name => null
,pi_column_value => null
,pi_error_message => 'See reqest log output for request $4'
);

when others
then

rollback;

l_event_details := sqlerrm;

xxexcpt_log_pub.initialize ('XXWSH_INVOICE_FILE_LOAD');
xxexcpt_log_pub.write_exception
(
pi_exception_type => xxexcpt_log_pub.g_excpt_type_system_explicit
,pi_exception_name => 'OTHERS'
,pi_parameters => null
,pi_location => l_event_text
,pi_location_details => l_event_details
,pi_package_name => 'XXWSH_INVOICE_FILE_LOAD'
,pi_procedure_name => 'WRITE_TO_STAGE_TABLES'
,pi_table_name => null
,pi_column_name => null
,pi_column_value => null
,pi_error_message => l_event_details
);

end;

/
commit;
exit
eof`
echo ${l_return}
}
Closed Thread

Bookmarks

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 09:21 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