我必须编写Oracle过程-存储过程应该将日期作为输入,并返回一个整数作为输出。存储过程文本如下所示:
DECLARE
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 --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;
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 ')
AND TERM_WEEKS = 0
AND MARKET = 'L'
ORDER BY CURRENCY_CODE, TERM_MONTHS;
--Check 3
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');
--Check 4
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');
SELECT ( (bbg_today - bbg_yest) * 100) / bbg_yest INTO retval1 FROM DUAL;
SELECT ( (drates_today - drates_yest) * 100) / drates_yest
INTO retval2
FROM DUAL;
SELECT ( (equity_today - equity_yest) * 100) / equity_yest
INTO retval3
FROM DUAL;
SELECT ( (index_today - index_yest) * 100) / index_yest
INTO retval4
FROM DUAL;
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;
DBMS_OUTPUT.put_line (retval);
END;
请帮助我编写正确的过程,并正确调用存储过程。
3条答案
按热度按时间fae0ux8s1#
过程的一个未经测试的粗略代码片段如下
ntjbwcob2#
创建一个函数而不是一个过程,并使用DATE输入参数。在
COUNT(*)
查询中删除order by,如果只选择count(*)
,它们就没有意义。plicqrtu3#
或者,您可以创建函数