【问题标题】:Oracle ORA-00936 Missing Expression Error with SubqueryOracle ORA-00936 子查询缺少表达式错误
【发布时间】:2016-05-31 22:03:32
【问题描述】:

我有一个通过 Oracle 11g 客户端连接到远程 Oracle 数据库的工作查询。为了合并基于别名的参数,我将此查询用作子查询,其中包含主查询中的参数。我看不出有什么问题——尽管很明显是这样——所以在我再研究这个小时之前,我想我会把代码提交给专家:

SELECT *
FROM
  (
  SELECT "UNITS"."UnitNumber", "UNITS"."ModelYear", "UNITS"."Make", "UNITS"."Model", "UNITS"."Class3", 
    "UNITS"."Class3Description", "UNITS"."TechnicalSpecification", SUBSTR("UNITS"."TechnicalSpecification", 13, 1) AS "FSC",
    "UNITS"."OwnerDepartment", "UNITS"."UnitStatus",
    CASE WHEN "UNITS"."Class3" = '1' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'F' THEN 'Y'
      WHEN ("UNITS"."Class3" = '10' OR "UNITS"."Class3" = '15') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'U' THEN 'Y'
      WHEN "UNITS"."Class3" = '11' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'D' THEN 'Y'
      WHEN ("UNITS"."Class3" = '2' OR "UNITS"."Class3" = '8' OR "UNITS"."Class3" = '18') AND 
    SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'C' THEN 'Y'
      WHEN ("UNITS"."Class3" = '3' OR "UNITS"."Class3" = '9' OR "UNITS"."Class3" = '17') AND 
    SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'B' THEN 'Y'
      WHEN "UNITS"."Class3" = '16' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'S' THEN 'Y'
      WHEN ("UNITS"."Class3" = '13' OR "UNITS"."Class3" = '4') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'L' THEN 'Y'
      WHEN ("UNITS"."Class3" = '12' OR "UNITS"."Class3" = '14') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'G' THEN 'Y'
      WHEN ("UNITS"."Class3" = '19' OR "UNITS"."Class3" = '20') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'R' THEN 'Y'
      WHEN "UNITS"."Class3" = '5' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'E' THEN 'Y'
      WHEN "UNITS"."Class3" = '6' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'H' THEN 'Y'
      ELSE ''
      END AS "MISMATCH"
  FROM "MFIVE"."VIEW_ALL_UNITS" "UNITS"
  WHERE  "UNITS"."OwnerDepartment" LIKE '580' AND "UNITS"."UnitStatus"='A'
  ) "U"
WHERE  "U"."MISMATCH" = {?Mismatch}
ORDER BY "U"."UnitNumber"

当我尝试运行此查询时,我收到“无法从数据库中检索日期”错误,ORA-00936:缺少表达式。

在我的一生中,我看不出问题出在哪里。任何帮助将不胜感激。

【问题讨论】:

  • 这是什么:{?不匹配}
  • 这会提示 Crystal Reports 13 请求参数。在这种情况下,缺少值将返回所有记录,而“Y”将仅返回 MISMATCH 别名 =“Y”的那些记录。
  • 那么也许你也应该用 CR 标记?如果您直接从 sql 运行查询会怎样?删除查询组件,直到问题消失,然后一次添加一个。那是其他人必须做的。由于您不提供表定义,因此无法运行此查询来查看如何修复它。
  • 我按照您的建议添加了 CR 标签。 • 由于系统的管理限制,我没有任何方法可以直接运行查询,所以我所能做的就是反复尝试在 CR 中运行它并根据反馈进行调整。 • 至于删除查询组件,没有太多要删除的,因为我知道整个子查询运行没有问题。问题在于前 3 行或最后两行。
  • 为什么所有的列名都是字符串文字?这是oracle的工作原理吗?看起来很邋遢,很难读写。

标签: sql oracle11g crystal-reports


【解决方案1】:

我可以看到您使过程复杂化...根据我的经验 Select * 格式在水晶中不起作用

如果您的要求是使用子查询,那么不要使用 * 取列名称,例如 select u.unitnumber ...... From(子查询)并在 Crystal Reports 中使用

编辑:------------------------------ -------------------- 一种选择是不使用*,而是使用如下查询所示的列名。

SELECT U.UnitNumber,U.ModelYear,U."Make", U."Model", U."Class3", 
    U."Class3Description", U."TechnicalSpecification", U."FSC",
    U."OwnerDepartment", U."UnitStatus", U.MISMATCH 
    FROM(
SELECT "UNITS"."UnitNumber", "UNITS"."ModelYear", "UNITS"."Make", "UNITS"."Model", "UNITS"."Class3", 
    "UNITS"."Class3Description", "UNITS"."TechnicalSpecification", SUBSTR("UNITS"."TechnicalSpecification", 13, 1) AS "FSC",
    "UNITS"."OwnerDepartment", "UNITS"."UnitStatus",
    CASE
    WHEN "UNITS"."Class3" = '1' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'F' THEN 'Y'
      WHEN ("UNITS"."Class3" = '10' OR "UNITS"."Class3" = '15') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'U' THEN 'Y'
      WHEN "UNITS"."Class3" = '11' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'D' THEN 'Y'
      WHEN ("UNITS"."Class3" = '2' OR "UNITS"."Class3" = '8' OR "UNITS"."Class3" = '18') AND 
    SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'C' THEN 'Y'
      WHEN ("UNITS"."Class3" = '3' OR "UNITS"."Class3" = '9' OR "UNITS"."Class3" = '17') AND 
    SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'B' THEN 'Y'
      WHEN "UNITS"."Class3" = '16' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'S' THEN 'Y'
      WHEN ("UNITS"."Class3" = '13' OR "UNITS"."Class3" = '4') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'L' THEN 'Y'
      WHEN ("UNITS"."Class3" = '12' OR "UNITS"."Class3" = '14') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'G' THEN 'Y'
      WHEN ("UNITS"."Class3" = '19' OR "UNITS"."Class3" = '20') AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'R' THEN 'Y'
      WHEN "UNITS"."Class3" = '5' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'E' THEN 'Y'
      WHEN "UNITS"."Class3" = '6' AND SUBSTR("UNITS"."TechnicalSpecification", 13, 1) <> 'H' THEN 'Y'
      ELSE ''
      END AS "MISMATCH"
  FROM "MFIVE"."VIEW_ALL_UNITS" "UNITS"
  WHERE  "UNITS"."OwnerDepartment" LIKE '580' AND "UNITS"."UnitStatus"='A') U
  WHERE  "U"."MISMATCH" = {?Mismatch}
ORDER BY "U"."UnitNumber"

第二个选项:

可能是查询的复杂性导致无法跟踪错误...因此您可以采取其他方式在add command 中进行简单查询,其余检查可以在本地水晶报告中进行,这很容易开发并跟踪错误。

试试下面的解决方案,让我知道你的意见。

使用此命令并在报告本身内部创建MisMatch

查询:

SELECT "UNITS"."UnitNumber", "UNITS"."ModelYear", "UNITS"."Make", "UNITS"."Model", "UNITS"."Class3", 
    "UNITS"."Class3Description", "UNITS"."TechnicalSpecification", SUBSTR("UNITS"."TechnicalSpecification", 13, 1) AS "FSC",
    "UNITS"."OwnerDepartment", "UNITS"."UnitStatus",
    FROM "MFIVE"."VIEW_ALL_UNITS" "UNITS"
  WHERE  "UNITS"."OwnerDepartment" LIKE '580' AND "UNITS"."UnitStatus"='A'

在报表设计中放置所需的列并创建一个公式MisMatch 并编写以下代码并将其放置在设计中。

@Mismatch 公式

    if   Class3  = '1' AND SUBSTR(  FSC , 13, 1) <> 'F' THEN 'Y'
else if (  Class3  = '10' OR   Class3  = '15') AND SUBSTR(  FSC , 13, 1) <> 'U' THEN 'Y'
else if   Class3  = '11' AND SUBSTR(  FSC , 13, 1) <> 'D' THEN 'Y'
else if (  Class3  = '2' OR   Class3  = '8' OR   Class3  = '18') AND
SUBSTR(  FSC , 13, 1) <> 'C' THEN 'Y'
else if (  Class3  = '3' OR   Class3  = '9' OR   Class3  = '17') AND
SUBSTR(  FSC , 13, 1) <> 'B' THEN 'Y'
else if   Class3  = '16' AND SUBSTR(  FSC , 13, 1) <> 'S' THEN 'Y'
else if (  Class3  = '13' OR   Class3  = '4') AND SUBSTR(  FSC , 13, 1) <> 'L' THEN 'Y'
else if (  Class3  = '12' OR   Class3  = '14') AND SUBSTR(  FSC , 13, 1) <> 'G' THEN 'Y'
else if (  Class3  = '19' OR   Class3  = '20') AND SUBSTR(  FSC , 13, 1) <> 'R' THEN 'Y'
else if   Class3  = '5' AND SUBSTR(  FSC , 13, 1) <> 'E' THEN 'Y'
else if   Class3  = '6' AND SUBSTR(  FSC , 13, 1) <> 'H' THEN 'Y'
ELSE ''

现在创建参数不匹配,我假设您的参数将具有 yN 并使用此参数来抑制报告中的数据。

去设计部分专家写下面的代码进行抑制。

if {?Mismatch}='Y'
then true
else false

试着告诉我结果

【讨论】:

  • 感谢您的尝试,但它会引发相同的错误。我使用了子查询,因为必须先为所有行计算别名“MISMATCH”,然后才能评估 {?Mismatch} 参数。我昨天在另一个查询中使用了完全相同的过程,所以我不知道是什么在 CR 的嘴里留下了不好的味道。
  • 在主查询中,您是否使用了列名而不是星号?如果不是这样检查
  • 我按照您的建议将星号替换为列名。它仍然抛出错误。
【解决方案2】:

虽然它没有回答为什么格式正确的参数会产生“缺少表达式”错误,但 Siva 建议的方法确实有效。感谢 Siva 的努力!

我确实尝试了其他一些更改,最明显的是确保参数名称和列名称不同。仍然返回相同的错误消息。

出于我的目的,如果我需要查看所有行或仅查看 MISMATCH = "Y" 的行,我将不得不硬编码 WHERE 子句中的参数值并运行单独的报告。远非理想,但它确实有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多