从shell脚本调用的oracle过程

时间:2014-05-20 13:46:37

标签: oracle

我有一个存储过程,如下所示执行正常 - 我正在运行Oracle SQL开发人员

  SET SERVEROUTPUT ON
    declare
    return_val number;
    BEGIN
    pm_own.emav_input_check(TO_DATE('04/19/2014','MM/DD/YYYY'),TO_DATE('04/20/2014','MM/DD/YYYY'),return_val);
   dbms_output.put_line(return_val);
    END;

存储过程 -

 create or replace
PROCEDURE        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;
   drates_today   NUMBER;
   equity_yest    NUMBER;
   equity_today   NUMBER;
   index_yest     NUMBER;
   index_today    NUMBER;
   retval         INTEGER;
   retval1        INTEGER;
   retval2        INTEGER;
   retval3        INTEGER;
   retval4        INTEGER;
BEGIN

   SELECT COUNT (*) INTO bbg_yest
     FROM Crd_Own.Bbg_Oiv v
     WHERE asof_date = last_bus_day;

   SELECT COUNT (*) INTO bbg_today
     FROM Crd_Own.Bbg_Oiv
     WHERE asof_date = price_date;


   SELECT COUNT (*) INTO drates_yest
       FROM pm_own.deposit_rates
       WHERE     asof_date = last_bus_day
            AND currency_code IN ('USD', 'EUR', 'GBP', 'JPY ')
            AND TERM_WEEKS = 0
            AND MARKET = 'L';

   SELECT COUNT (*) INTO drates_today
       FROM pm_own.deposit_rates
       WHERE     asof_date = price_date
            AND currency_code IN ('USD','EUR', 'GBP', 'JPY ')
            AND TERM_WEEKS = 0
            AND MARKET = 'L';

   SELECT COUNT (*) INTO equity_yest
       FROM pm_own.BDVD_FORECAST_EQUITY
       WHERE asof_date = last_bus_day;

   SELECT COUNT (*) INTO equity_today
       FROM pm_own.BDVD_FORECAST_EQUITY
       WHERE asof_date = price_date;


   SELECT COUNT (*) INTO index_yest
       FROM pm_own.BDVD_FORECAST_INDEX
       WHERE asof_date = last_bus_day;

   SELECT COUNT (*) INTO index_today
       FROM pm_own.BDVD_FORECAST_INDEX
       WHERE asof_date = price_date;

   IF bbg_yest != 0
   THEN
     SELECT ( (bbg_today - bbg_yest) * 100) / bbg_yest INTO retval1
     FROM DUAL;
   ELSE
     retval1 := 0;
   END IF;

   IF drates_yest != 0
   THEN
     SELECT ( (drates_today - drates_yest) * 100) / drates_yest INTO retval2
     FROM DUAL;
   ELSE
     retval2 := 0;
   END IF;

   IF equity_yest != 0
   THEN
     SELECT ( (equity_today - equity_yest) * 100) / equity_yest INTO retval3
     FROM DUAL;
   ELSE
     retval3 := 0;
   END IF;

   IF index_yest != 0
   THEN
     SELECT ( (index_today - index_yest) * 100) / index_yest INTO retval4
     FROM DUAL;
   ELSE
     retval4 := 0;
   END IF;


   retval := 0;

   IF retval1 < 0 AND ABS (retval1) > 20
   THEN
      retval := 1;
   ELSIF retval2 < 0 AND ABS (retval2) > 20
   THEN
      retval := 2;
   ELSIF retval3 < 0 AND ABS (retval3) > 20
   THEN
      retval := 3;
   ELSIF retval4 < 0 AND ABS (retval4) > 20
   THEN
      retval := 4;
   END IF;

   o_param := retval;
END;


    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')         
    AND currency_code IN (' USD', 'EUR', 'GBP', 'JPY ')
    AND TERM_WEEKS = 0;

    SELECT COUNT (*) INTO drates_today
    FROM pm_own.deposit_rates
    WHERE     asof_date = TO_DATE ('price_date', 'mm/dd/yyyy')
    AND currency_code IN (' USD', 'EUR', 'GBP', 'JPY ');

    SELECT COUNT (*) INTO equity_yest
    FROM pm_own.BDVD_FORECAST_EQUITY
    WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');

    SELECT COUNT (*) INTO equity_today
    FROM pm_own.BDVD_FORECAST_EQUITY
    WHERE asof_date = TO_DATE ('price_date', 'mm/dd/yyyy');


    SELECT COUNT (*) INTO index_yest
    FROM pm_own.BDVD_FORECAST_INDEX
    WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');

    SELECT COUNT (*) INTO index_today
    FROM pm_own.BDVD_FORECAST_INDEX
    WHERE asof_date = TO_DATE ('price_date', '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;

    IF drates_yest != 0
    THEN
    SELECT ( (drates_today - drates_yest) * 100) / drates_yest INTO retval2
    FROM DUAL;
    ELSE
    retval2 := 0;
    END IF;

    IF equity_yest != 0
    THEN
    SELECT ( (equity_today - equity_yest) * 100) / equity_yest INTO retval3
    FROM DUAL;
    ELSE
    retval3 := 0;
    END IF;

    IF index_yest != 0
    THEN
    SELECT ( (index_today - index_yest) * 100) / index_yest INTO retval4
    FROM DUAL;
    ELSE
    retval4 := 0;
    END IF;


    retval := 0;

    IF retval1 < 0 AND ABS (retval1) > 20
    THEN
    retval := 1;
    ELSIF retval2 < 0 AND ABS (retval2) > 20
    THEN
    retval := 2;
    ESIF retval3 < 0 AND ABS (retval3) > 20
    THEN
    retval := 3;
    ELSIF retval4 < 0 AND ABS (retval4) > 20
    THEN
    retval := 4;
    END IF;

    o_param := retval;
    END;

但现在当我尝试从shell脚本调用上述过程为 -

  #!/bin/bash

  price_date="05/20/2014"

  last_bus_day="05/19/2014"

  ORAPWD=`cat /appl/${ENV_BASE}data/data/U/control/.xfile_svc_op`


    model_check=`sqlplus -s` <<....END
    svc_op/${ORAPWD}@${ORACLE_SERVER}
    var return_val number;
    set feedback off
    set heading off
    set pagesize 0
    execute PM_OWN.emav_input_check(TO_DATE($last_bus_day,'MM/DD/YYYY'),TO_DATE($price_date,'MM/DD/YYYY'),:return_val);
    print return_val;
....END
echo $model_check

*Please correct me where I am wrong.here ORAPWD and ORACLE_SERVER having valid values.My requirement is get the value returned from stored procedure .please let me know where am i missing.Any help will be highly appreciated.

感谢*

1 个答案:

答案 0 :(得分:0)

由于您没有提供有关错误消息/错误输出的任何信息/无论您获得什么,我只能猜测。这(以及所有后续条件)都是错误的:

WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');

这会尝试将文字字符串price_date转换为日期。您可能的意思是

WHERE asof_date = TO_DATE (last_bus_day, 'mm/dd/yyyy');

(注意last_bus_day周围没有')。但这仍然是错误的,因为last_bus_day 已经一个日期。

假设您要返回其日期部分(没有时间信息)等于最后一个总线日的所有行,您可以使用

WHERE trunc(asof_date) = trunc(last_bus_day)

TRUNC - 如果在没有格式说明符的情况下使用 - 返回DATE值的日期部分。