spacetanker spacetanker - 6 months ago 17
SQL Question

Oracle ORA-00936 Missing Expression Error with Subquery

I have a working query that connects to a remote Oracle database through the Oracle 11g Client. To incorporate a parameter based on an alias I used this query as a subquery with the parameter in the main query. I don't see anything the matter - though something obviously is - so before I grind on this for another hour I thought I would pose the code to the experts:

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"


When I attempt to run this query I recieve a "Failed to retrieve date from the database" error, ORA-00936: missing expression.

For the life of me I can't see what the problem is. Any assistance will be appreciated.

Answer

I can see you are complicating the process...to my experience Select * format doesnt work in crystal

If your requirement is to use sub query then instead of * take column names like select u.unitnumber ...... From (sub query) and use in Crystal Reports

Edit:----------------------------------------------------------------- One option is not to use the * and use column names as shown in below query.

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"

Second Option:

May be complexity of the query is making it impossible to trace the error... So you can do other way around take simple query in add command rest of the checking you can do in crystal reports locally which will be easy to develop and also trace the errors.

Try below solution and let me know your input.

Use this command and create the MisMatch internally in the report itself.

Query:

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'

Place required columns in report design and create a formula MisMatch and write below code and place it on design.

@Mismatch formula

    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 ''

Now create parameter mismatch and I assume your parameter will have either y or N and use this paramter to supress the data in report.

Go to section expert of the design write below code for supress.

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

Try and let me know the result

Comments