简体   繁体   中英

Dreaded "Missing Right Parenthesis" Error in Oracle SQL

We access an Oracle database through a web application. The web application is published, hosted and administered off-site. One component of the web application are dashboards, which use SQL to return data from the system on regular intervals that are then displayed and can trigger alarms should certain thresholds be reached.

The SQL has several parameters that are assigned in the dashboard setup: LOCATION, OWNER_DEPT, USING_DEPT and DAYS_AHEAD and appear to be working properly. Here is the query:

SELECT * FROM
(
SELECT DISTINCT 
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" AS "UNIT NO", "MFIVE"."VIEW_WORK_REQ_OCC"."WORK_REQ_NO" AS "WORK REQ NO", "MFIVE"."VIEW_WORK_REQ_OCC"."JOB" AS "JOB", 
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE", 
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."FIRST_DATE") END AS "FIRST DATE", 
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE" IS NULL THEN NULL ELSE ("MFIVE"."VIEW_WORK_REQ_OCC"."LAST_DATE") END AS "LAST DATE"
FROM "MFIVE"."VIEW_WORK_REQ_OCC"
WHERE
("MFIVE"."VIEW_WORK_REQ_OCC"."MNT_PREVENTIVE_FL" = 'Y') AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."LOCATION") LIKE UPPER(CONCAT(CONCAT('%', ':<LOCATION>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."OWNER_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<OWNER_DEPT>'), '%'))) AND
(UPPER("MFIVE"."VIEW_WORK_REQ_OCC"."USING_DEPT") LIKE UPPER(CONCAT(CONCAT('%', ':<USING_DEPT>'), '%'))) AND
("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" >= SYSDATE + ':<DAYS_AHEAD>')
ORDER BY 
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC, 
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC, 
CASE WHEN "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE" IS NULL THEN NULL ELSE         ("MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE") END AS "DUE DATE" ASC
)

The issue is with the statements involving "MFIVE"."VIEW_WORK_REQ_OCC"."DUE_DATE". We're attempting to return only values where DUE_DATE is greater than the SYSDATE plus the value in the DAYS_AHEAD parameter. Deleting these lines allows the query to execute properly; leaving them as-is returns the error ORA-00907: missing right parenthesis.

The majority of the SQL was lifted from the SQL as generated by an ad-hoc reporting component of the web application. The report runs properly, but we are not able to pass parameters through the ad-hoc reporting module. The modifications to the original were to add the bind variables.

I'm hoping someone can point me in the correct direction to remedy this issue. Any assistance is appreciated.

Thanks to Kaushik Nayak for helping me see the forest for the trees.

The correction only affects the ORDER BY clause:

...
ORDER BY 
"MFIVE"."VIEW_WORK_REQ_OCC"."UNIT_NO" ASC, 
"MFIVE"."VIEW_WORK_REQ_OCC"."JOB" ASC, 
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM