如果在oracle中使用select查询条件

时间:2014-08-25 13:36:59

标签: oracle

如何在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;

1 个答案:

答案 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;