Oracle ORA-00936子查询缺少表达式错误

时间:2016-05-27 16:57:06

标签: sql oracle11g crystal-reports

我有一个通过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:缺少表达式。

对于我的生活,我看不出问题所在。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

如果你的要求是使用子查询,那么取代*取名列如select u.unitnumber ...... from(sub query)并在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,并使用此参数来压缩报告中的数据。

转到下面的设计部分专家写下supress的代码。

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

尝试让我知道结果

答案 1 :(得分:0)

虽然它没有回答为什么正确格式化的参数会产生“缺失表达式”错误,但Siva建议的方法确实有效。为Siva提供额外的功劳!

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

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