Oracle Case语句列定义不明确[重复]

zpgglvta  于 2022-12-22  发布在  Oracle
关注(0)|答案(1)|浏览(192)
    • 此问题在此处已有答案**:

ORA-00984: column not allowed here [duplicate](1个答案)
2天前关闭。
下面我尝试使用一个case语句,当我添加带箭头的行时,我得到这个错误。
ORA-00918:列定义不明确00918. 00000-"列定义不明确"* 原因:

  • 操作:行出错:71列:44
CASE
     WHEN CUST200.TAX_NUMBER is null THEN 2         
>>>> WHEN CUST200.TAX_NUMBER in ("I/C","BRANCH") THEN 1
     WHEN CUST200.ACCOUNT_NUMBER in (8001,5201) THEN 1
     ELSE 2
   END                                         "IC",

我尝试将该行重新格式化为其他语法,如= ANY("I/C","BRANCH")THEN 1,但得到相同的错误。即使删除行"WHEN CUST200.TAX_NUMBER is null THEN 2",我仍然得到相同的错误。但是,如果删除有问题的行,"WHEN CUST200.TAX_NUMBER is null THEN 2"可以正常工作。

nle07wnf

nle07wnf1#

您应该使用单引号,而不是双引号a这样做,Oracle * 认为 * 您指的是列名(而您不是)。

SQL> WITH
  2     cust200 (tax_number, account_number)
  3     AS
  4        (SELECT 'I/C', 8001 FROM DUAL
  5         UNION ALL
  6         SELECT NULL, 5201 FROM DUAL)
  7  SELECT CASE
  8            WHEN cust200.tax_number IS NULL THEN 2
  9            WHEN cust200.tax_number IN ('I/C', 'BRANCH') THEN 1
 10            WHEN cust200.account_number IN (8001, 5201) THEN 1
 11            ELSE 2
 12         END res
 13    FROM cust200;

       RES
----------
         1
         2

SQL>

相关问题