如何在Oracle中使用选择查询使用IF条件。请建议
IF (SELECT ptr_forecast_dt from ptr_details WHERE ptr_line_id = prmptr_line_id AND ptr_actual_dt IS NULL) IS NOT NULL THEN
SELECT ptr_forecast_dt INTO Forcast_dt from ptr_details WHERE ptr_line_id = prmptr_line_id AND ptr_actual_dt IS NULL;
END IF;
答案 0 :(得分:2)
您可以在WHERE子句中添加另一个条件,如下所示:
SELECT ptr_forecast_dt
INTO Forcast_dt
FROM ptr_details
WHERE ptr_line_id = prmptr_line_id
AND ptr_actual_dt IS NULL
AND ptr_forecast_dt IS NOT NULL;
如果要在ptr_forecast_dt为NULL时插入备用值,则可以使用NVL函数,如下所示:
SELECT NVL(ptr_forecast_dt, TO_DATE('01/01/2014', 'MM/DD/YYYY'))
INTO Forcast_dt
FROM ptr_details
WHERE ptr_line_id = prmptr_line_id
AND ptr_actual_dt IS NULL;