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 = 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;
上面显示的代码是程序。当我执行它 -
declare
return_val number;
BEGIN
pm_own.emav_input_check(TO_DATE('05/19/2014','MM/DD/YYYY'),TO_DATE('05/20/2014','MM/DD/YYYY'),return_val);
dbms_output.put_line(return_val);
END;
我收到以下错误:
Error report:
ORA-01858: a non-numeric character was found where a numeric was expected
ORA-06512: at "PM_OWN.EMAV_INPUT_CHECK", line 19
ORA-06512: at line 4
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
知道如何修复此错误吗?
答案 0 :(得分:1)
问题在于你如何使用INCOMING参数。这是你的代码:
SELECT COUNT (*) INTO bbg_yest
FROM Crd_Own.Bbg_Oiv v
WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');
'last_bus_day'是一个常量字符串。 Oracle尝试将mm(月份作为数字)从中取出并失败。
你的参数:last_bus_day IN DATE
因此您无需再进行任何转换:
SELECT COUNT (*) INTO bbg_yest
FROM Crd_Own.Bbg_Oiv v
WHERE asof_date = last_bus_day;
答案 1 :(得分:1)
SELECT COUNT (*) INTO bbg_yest
FROM Crd_Own.Bbg_Oiv v
WHERE asof_date = TO_DATE ('last_bus_day', 'mm/dd/yyyy');
这些是不有效查询。 to_date
函数需要一个表示日期的字符串,以及一个表示第一个参数是什么格式的格式字符串。 Last_bus_day
与mm/dd/yyyy
不匹配,因此失败。匹配字符串的示例是05/19/2014
。
由于您的传入参数是日期,因此您应该将查询更改为:
SELECT COUNT (*) INTO bbg_yest
FROM Crd_Own.Bbg_Oiv v
WHERE asof_date = last_bus_day;
因为您不需要将字符串转换为日期,然后再转换为日期。