0

我正在尝试在 WHERE 子句中执行以下 CASE 语句,但它不起作用。我到处搜索,找不到解决方案。错误报告说:

PL/SQL: ORA-00905: missing keyword.

缺少哪个关键字?

SELECT COUNT(*)
    INTO v_sql_count
    FROM xaction_level_info b
    WHERE v_measure_map(i).v_upload_code = b.UPLOAD_CODE
    AND v_xs_scope(j).v_scope_key        = b.SCOPE
    AND 

    CASE WHEN
    v_measure_map(i).v_date_stamp='Benchmark_Date' THEN 
    v_xs_scope(j).v_enriched_date BETWEEN NVL(b.effective_start_time, 00000000000000) AND NVL(b.effective_end_time, 99999999999999)
    ELSE
    v_xs_scope(j).v_enriched_time BETWEEN NVL(b.effective_start_time, 00000000000000) AND NVL(b.effective_end_time, 99999999999999) 
    END
    AND b.level_order =
      (SELECT MIN(level_order)
      FROM xaction_level_info
      WHERE SCOPE                                   = b.SCOPE
      AND UPLOAD_CODE                               = b.UPLOAD_CODE
      AND NVL(effective_start_time, 00000000000000) = NVL(b.effective_start_time, 00000000000000)
      AND NVL(effective_end_time, 99999999999999)   = NVL(b.effective_end_time, 99999999999999)
      ) ;

我尝试了这种方法,但它没有给我想要的结果。有人可以解释为什么吗?无论 Enriched_Date 是否在 date_stamp 字段中,Oracle 似乎只使用 v_xs_scope(j).v_enriched_time。

    CASE WHEN
    v_measure_map(i).v_date_stamp='Enriched_Date' THEN 
    v_xs_scope(j).v_enriched_date
    when 
    v_measure_map(i).v_date_stamp='Benchmark_Date' THEN 
    v_xs_scope(j).v_benchmark_date
    ELSE
    v_xs_scope(j).v_enriched_time 
    END
    BETWEEN NVL(b.effective_start_time, 00000000000000) AND NVL(b.effective_end_time, 99999999999999) 
4

1 回答 1

1

CASE您可以只使用OR表达式来考虑这两个选项,而不是使用表达式。

SELECT COUNT(*) -- Match for measure value on these keys.
        INTO v_sql_count
        FROM xaction_level_info b
        WHERE v_measure_map(i).v_upload_code = b.UPLOAD_CODE
        AND v_xs_scope(j).v_scope_key        = b.SCOPE
        AND (
                (
                v_measure_map(i).v_date_stamp='Benchmark_Date'
                AND v_xs_scope(j).v_enriched_date BETWEEN NVL(b.effective_start_time, 00000000000000) AND NVL(b.effective_end_time, 99999999999999)
                )
            OR
                (
                v_measure_map(i).v_date_stamp<>'Benchmark_Date'
                AND v_xs_scope(j).v_enriched_time BETWEEN NVL(b.effective_start_time, 00000000000000) AND NVL(b.effective_end_time, 99999999999999) 
                )
            )
        AND b.level_order =
          (SELECT MIN(level_order)
          FROM xaction_level_info
          WHERE SCOPE                                   = b.SCOPE
          AND UPLOAD_CODE                               = b.UPLOAD_CODE
          AND NVL(effective_start_time, 00000000000000) = NVL(b.effective_start_time, 00000000000000)
          AND NVL(effective_end_time, 99999999999999)   = NVL(b.effective_end_time, 99999999999999)
          ) ;  
于 2013-05-09T21:48:16.277 回答