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 runtime parm to at -f shell script island360 Shell Programming and Scripting 1 10-28-2007 12:59 PM
cron job problem, passing a parm bheemsen Shell Programming and Scripting 12 03-14-2007 10:31 AM
Passing Values from a shell script dhananjaysk Shell Programming and Scripting 6 04-06-2006 10:33 AM
Script to submit a job with date parm in maestro Kirojin Shell Programming and Scripting 1 03-21-2006 04:11 PM
passing awk variable to the shell script bcheaib Shell Programming and Scripting 3 07-21-2004 11:00 AM

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 02-19-2008
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
Angry Passing the value of Out parm in SP to UNIX Shell Script

I have a simple procedure which accepts two input parms and returns and output count:

CREATE OR REPLACE Procedure GET1 ( IN_FOLDER IN VARCHAR2,
IN_SUBJECT_AREA IN VARCHAR2,
OUT_CNT IN OUT VARCHAR2
)
AS
BEGIN
select count(*)
into OUT_CNT
from REP_WFLOW_RUN
where subject_area = IN_FOLDER
and workflow_name = IN_SUBJECT_AREA
and end_time is null
order by end_time desc;

END GET1 ;
/

If I execute it in SQL*PLUS, with following code:

SET SERVEROUTPUT ON
DECLARE
v_folder_name varchar2(20) ;
v_wf_name varchar2(20) ;
v_cnt varchar2(20) ;
BEGIN

v_folder_name := '~user1' ;
v_wf_name := 'w_Workflow2';

GET1(v_folder_name, v_wf_name,v_cnt) ;
DBMS_OUTPUT.PUT_LINE('Folder:' || v_folder_name || ' Wf:' || v_wf_name ||' cnts:' || v_cnt);
END;
/


It returns corrrect value

Folder:~user1 Wf:w_Workflow2 cnts:1

Now how can I get this return value from SP into a UNIX shell Script variable??


I tried following shell script:

wf_name="w_Workflow2"
sub_area="~user1"

echo "wf name :" $wf_name
echo "sub_area:" $sub_area
echo "REP User:" $REP_READ_ONLY_USR
echo "REP PASS:" $REP_READ_ONLY_PASS

v_cnt=6

return_cc=`sqlplus << EOINPUT
##sqlplus << EOINPUT
$REP_READ_ONLY_USR/$REP_READ_ONLY_PASS@dadev
set echo off
set feedback off
set serveroutput on
set verify off
whenever sqlerror exit 1
@/etlapps/SrcFiles/SPD/exec_sp.sql $sub_area $wf_name $v_cnt
exit
##EOINPUT
EOINPUT`

echo "out cnt:" $v_cnt
echo "return cc:" $return_cc

I don't get the value in shell script.

I also tried to use a BIND Variable in my anonymous SQL that runs the SP as follows:

SET SERVEROUTPUT ON
DECLARE
v_folder_name varchar2(20) ;
v_wf_name varchar2(20) ;
var v_cnt varchar2(20) := $v_cnt ;
BEGIN

v_folder_name := '~user1' ;
v_wf_name := 'w_Workflow2';

GET1(v_folder_name, v_wf_name,:v_cnt) ;
DBMS_OUTPUT.PUT_LINE('Folder:' || v_folder_name || ' Wf:' || v_wf_name ||' cnts:' || v_cnt);
END;
/

I get error that Bind variable $v_cnt not declared.

What am I doing wrong????
  #2 (permalink)  
Old 02-19-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
Could you try following and let me know how it goes

====================
#!/bin/sh

wf_name="w_Workflow2"
sub_area="~user1"

echo "wf name :" $wf_name
echo "sub_area:" $sub_area
echo "REP User:" $REP_READ_ONLY_USR
echo "REP PASS:" $REP_READ_ONLY_PASS

return_cc=`sqlplus -s $REP_READ_ONLY_USR/$REP_READ_ONLY_PASS@dadev << EOINPUT
set echo off
set feedback off
set serveroutput on
set verify off
DECLARE
v_folder_name varchar2(20) ;
v_wf_name varchar2(20) ;
rec_cnt number;
BEGIN
v_folder_name := $sub_area ;
v_wf_name := $wf_name;
GET1(v_folder_name, v_wf_name,rec_cnt) ;
DBMS_OUTPUT.PUT_LINE(rec_cnt);
END;
/
EXIT;
EOINPUT`

echo "Record count is : [$return_cc]"
============================
  #3 (permalink)  
Old 02-19-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Assuming the stored procedure is already created in the db, create a "sql_script.sql" like this:

Code:
SET SERVEROUTPUT ON
DECLARE
   v_folder_name varchar2(20) ;
   v_wf_name varchar2(20) ;
   v_cnt varchar2(20) ;

BEGIN
   v_folder_name := '~user1' ;
   v_wf_name := 'w_Workflow2';
   GET1(v_folder_name, v_wf_name,v_cnt) ;
   DBMS_OUTPUT.PUT_LINE(v_cnt);
END;
/

...and this is the shell code:

Code:
wf_name="w_Workflow2"
sub_area="~user1"

echo "wf name :" $wf_name
echo "sub_area:" $sub_area
echo "REP User:" $REP_READ_ONLY_USR
echo "REP PASS:" $REP_READ_ONLY_PASS

v_cnt=6

return_cc=`sqlplus -s /nolog <<EOINPUT
connect $REP_READ_ONLY_USR/$REP_READ_ONLY_PASS@dadev
set echo off
set feedback off
set serveroutput on
set verify off
whenever sqlerror exit 1
@sql_script.sql $sub_area $wf_name $v_cnt
exit
EOINPUT`

echo "return cc:" $return_cc

The resulting "$return_cc" value is actually the new v_cnt value. It's useless to print out other things with DBMS_OUTPUT: you already know the values of sub_area and wf_name!
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 10:37 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