Search code examples
oracle-databaseselectora-00907

Oracle query getting ORA-00907: missing right parenthesis


I've read through the other missing right parenthesis questions and haven't found an answer to my problem. I assume it is a syntax error cutting things off before the end (I'm not really an Oracle guy) but I don't know where it is. The query is supposed to pull the customer ID and the latest year there is a record for that customer. The parameters are a customer ID number (unique by district but different from the organizational one), the district, and the year being searched. If there is no record for the searched year for that district, no records should be returned.

SELECT DISTINCT CUSTOMER.CUSTOMER_ID_ALT, tblMaxYear.maxYear 
FROM CUSTOMER CROSS JOIN 
  (SELECT to_char(Max(tblYr.FISCAL_YEAR), 'YYYY') AS maxYear     
  FROM CUSTOMER AS tblYr 
  WHERE tblYr.DISTRICT_KEY= :district
      AND tblYr.CUSTOMER_ID= :cust) tblMaxYear 
WHERE CUSTOMER.DISTRICT_KEY=:district
   AND CUSTOMER.CUSTOMER_ID= :cust
   AND to_char(CUSTOMER.FISCAL_YEAR, 'YYYY') = :prmYear

Solution

  • Remove the AS in:

    FROM CUSTOMER AS tblYr
    

    AS can be used for column aliasing, not table aliasing