title: How can I return an OUT parameter from a procedure to a shell script?
body: <p>I have created a procedure:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE PM_OWN.emav_input_check(last_bus_day IN DATE,
      price_date IN DATE, o_param OUT NUMBER)
  AS
  
  bbg_yest       NUMBER;
  bbg_today      NUMBER;
  drates_yest    NUMBER;
  
  BEGIN
  
  SELECT COUNT (*) INTO bbg_yest
  FROM Crd_Own.Bbg_Oiv v
  WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');
  
  SELECT COUNT (*) INTO bbg_today
  FROM Crd_Own.Bbg_Oiv
  WHERE asof_date = TO_DATE ('price_date', 'mm/dd/yyyy');
  
  SELECT COUNT (*) INTO drates_yest
  FROM pm_own.deposit_rates
  WHERE     asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy')
  
  IF bbg_yest != 0
  THEN
  SELECT ( (bbg_today - bbg_yest) * 100) / bbg_yest INTO retval1
  FROM DUAL;
  ELSE
  retval1 := 0;
  END IF;
  
  -----
  -----
   retval := 0;
  
   IF retval1 &lt; 0 AND ABS (retval1) &gt; 20
   THEN
   retval := 1;
   ELSIF retval2 &lt; 0 AND ABS (retval2) &gt; 20
   THEN
   retval := 2;
   ELSIF retval3 &lt; 0 AND ABS (retval3) &gt; 20
   THEN
   retval := 3;
   ELSIF retval4 &lt; 0 AND ABS (retval4) &gt; 20
   THEN
   retval := 4;
   END IF;
   o_param := retval;
  END;
  </code></pre>
  
  <p>This basically procedure returns some value ,and procedure being called from some shell script.</p>
  
  <pre><code> #!/bin/sh
  
   last_bus_day=`adjust_business_date -date $price_date -adj -1 -adj_type D`
  
   ORAPWD=`cat /appl/${ENV_BASE}data/data/U/control/.xfile_${ORA_ENV_OP}`
  
   return_val=0
  
   job_id &lt;&lt;....END
   model_check=`sqlplus -s` &lt;&lt;....END
   ${ORA_ENV_OP}/${ORAPWD}@${ORACLE_SERVER}
  
   var return_val number;
  
   execute PM_OWN.emav_input_check($last_bus_day,$price_date,:return_val);
  
   commit;
   exit;
  
   ....END
  </code></pre>
  
  <p>I want to use the value returned by stored procedure further in the shell script.</p>
  
  <p>I think <code>return_val</code> gets the value returned by the procedure, but how can I use that later in the shell script, as <code>$return_val</code>?</p>
  
  <p>Basically my procedure was part of the script:</p>
  
  <pre><code> last_bus_day=`adjust_business_date -date $price_date -adj -1 -adj_type D`
  
   ORAPWD=`cat /appl/${ENV_BASE}data/data/U/control/.xfile_${ORA_ENV_OP}`
  
   job_id &lt;&lt;....END
  
   model_check=`sqlplus -s` &lt;&lt;....END
  
   ${ORA_ENV_OP}/${ORAPWD}@${ORACLE_SERVER}
   set heading off
   declare bbg_yest number;
   bbg_today number;
   drates_yest number;
   drates_today number;
  
  
   begin
  
   --Check 1
   select count(*) into bbg_yest
   from   Crd_Own.Bbg_Oiv v
   where  asof_date =  TO_DATE('$last_bus_day','mm/dd/yyyy');
  
  select count(*) into bbg_today
  from   Crd_Own.Bbg_Oiv v
   where  asof_date =  TO_DATE('$price_date','mm/dd/yyyy');
  
  --Check 2
   select count(*) into drates_yest
   from   pm_own.deposit_rates
   where  asof_date = TO_DATE('$last_bus_day','mm/dd/yyyy') and currency_code in (' USD','EUR','GBP','JPY  ') AND    TERM_WEEKS = 0 AND MARKET = 'L' ORDER BY CURRENCY_CODE, TERM_MONTHS;
  
   --------
    -------and so on
  
  
   if retval1 &lt; 0 and abs(retval1) &gt; 20 then
      retval := 1;
    elsif retval2 &lt; 0 and abs(retval2) &gt; 20 then
     retval := 2;
  elsif retval3 &lt; 0 and abs(retval3) &gt; 20 then
     retval := 3;
  elsif retval4 &lt; 0 and abs(retval4) &gt; 20 then
     retval := 4;
  end if;
  
  dbms_output.put_line(retval);
  
  end
  
  ....END
  </code></pre>
  
  <p>Now I'm replacing the code from the script with the procedure call.</p>