ORA-00907缺少右括号在Crystal中 - 在Oracle Developer中工作

时间:2015-02-24 14:55:04

标签: sql oracle oracle11g crystal-reports oracle-sqldeveloper

我遇到了一个查询问题,它在Oracle Developer中工作正常,{?Month}替换为'2015-01-01',但在Crystal中,使用下面的查询时,它给出了错误ORA-00907 missing right parenthesis

参数

  

参数名称:月

     

提示文字:输入月份

     

值类型:字符串(也尝试过日期)

     

默认值:2015-01-01 00:00:00 AM

代码

SELECT /*+ ordered_predicates */
ACTIVE_SEPARATE.WO_NO, ACTIVE_SEPARATE.MCH_CODE,
(SELECT DISTINCT CASE WHEN MCH_CODE LIKE '%-%' THEN TRIM(SUBSTR(MCH_CODE, 0, INSTR(MCH_CODE, '-')-1)) ELSE MCH_CODE END FROM ACTIVE_SEPARATE ACTIVE_SEPARATE_SUB WHERE ACTIVE_SEPARATE.MCH_CODE = ACTIVE_SEPARATE_SUB.MCH_CODE) AS MCH_CODE_TRIM,
(SELECT DISTINCT CASE WHEN MCH_NAME LIKE '%-%' THEN TRIM(SUBSTR(MCH_NAME, 0, INSTR(MCH_NAME, '-')-1)) ELSE MCH_NAME END FROM EQUIPMENT_FUNCTIONAL WHERE ACTIVE_SEPARATE.MCH_CODE = EQUIPMENT_FUNCTIONAL.MCH_CODE) AS MCH_NAME_TRIM,
MCH_TYPE, ACTIVE_SEPARATE.REQUIRED_START_DATE, ACTIVE_SEPARATE.ERR_DESCR,
(24 * ((REAL_F_DATE) - (REQUIRED_START_DATE))) as BREAKDOWN_HOURS,
(100 - ((((last_day(to_date({?Month}, 'yyyy-mm-dd'))) -  trunc(to_date({?Month}, 'yyyy-mm-dd'), 'month'))*24) + 24) - (( (REAL_F_DATE) - (REQUIRED_START_DATE))* 24)) / ((24 * ((last_day(to_date({?Month}, 'yyyy-mm-dd'))) - trunc(to_date({?Month}, 'yyyy-mm-dd'), 'month'))) + 24) AS PERCENTAGE_AVAILABILITY
FROM ACTIVE_SEPARATE
RIGHT JOIN EQUIPMENT_FUNCTIONAL ON EQUIPMENT_FUNCTIONAL.MCH_CODE = (SELECT DISTINCT CASE WHEN MCH_CODE LIKE '%-%' THEN TRIM(SUBSTR(MCH_CODE, 0, INSTR(MCH_CODE, '-')-1)) ELSE MCH_CODE END FROM ACTIVE_SEPARATE ACTIVE_SEPARATE_SUB WHERE ACTIVE_SEPARATE.MCH_CODE = ACTIVE_SEPARATE_SUB.MCH_CODE)
WHERE ERR_CLASS = '001'
AND MCH_TYPE IS NOT NULL
AND ACTIVE_SEPARATE.REQUIRED_START_DATE BETWEEN
(trunc(to_date({?Month}, 'yyyy-mm-dd'),'month')
AND
last_day({?Month}))

UNION

SELECT /*+ ordered_predicates */
HISTORICAL_SEPARATE.WO_NO, HISTORICAL_SEPARATE.MCH_CODE,
case when (TRIM(SUBSTR(HISTORICAL_SEPARATE.MCH_CODE, 0, INSTR(HISTORICAL_SEPARATE.MCH_CODE, '-')-1))) is null then HISTORICAL_SEPARATE.MCH_CODE else(TRIM(SUBSTR(HISTORICAL_SEPARATE.MCH_CODE, 0, INSTR(HISTORICAL_SEPARATE.MCH_CODE, '-')-1))) end as MCH_CODE_TRIM,
case when (TRIM(SUBSTR(EQUIPMENT_FUNCTIONAL.MCH_NAME, 0, INSTR(EQUIPMENT_FUNCTIONAL.MCH_NAME, '-')-1))) is null then EQUIPMENT_FUNCTIONAL.MCH_NAME else(TRIM(SUBSTR(EQUIPMENT_FUNCTIONAL.MCH_NAME, 0, INSTR(EQUIPMENT_FUNCTIONAL.MCH_NAME, '-')-1))) end as MCH_NANME_TRIM,
MCH_TYPE,  HISTORICAL_SEPARATE.REQUIRED_START_DATE, HISTORICAL_SEPARATE.ERR_DESCR,
(24 * ((REAL_F_DATE) - (REQUIRED_START_DATE))) as BREAKDOWN_HOURS,
(100 - ((((last_day(to_date({?Month}, 'yyyy-mm-dd'))) -  trunc(to_date({?Month}, 'yyyy-mm-dd'), 'month'))*24) + 24) - (( (REAL_F_DATE) - (REQUIRED_START_DATE))* 24)) / ((24 * ((last_day(to_date({?Month}, 'yyyy-mm-dd'))) - trunc(to_date({?Month}, 'yyyy-mm-dd'), 'month'))) + 24) AS PERCENTAGE_AVAILABILITY
FROM HISTORICAL_SEPARATE
RIGHT JOIN EQUIPMENT_FUNCTIONAL ON EQUIPMENT_FUNCTIONAL.MCH_CODE = (SELECT DISTINCT CASE WHEN MCH_CODE LIKE '%-%' THEN TRIM(SUBSTR(MCH_CODE, 0, INSTR(MCH_CODE, '-')-1)) ELSE MCH_CODE END FROM HISTORICAL_SEPARATE HISTORICAL_SEPARATE_SUB WHERE HISTORICAL_SEPARATE.MCH_CODE = HISTORICAL_SEPARATE_SUB.MCH_CODE)
WHERE ERR_CLASS = '001'
AND MCH_TYPE IS NOT NULL
AND HISTORICAL_SEPARATE.REQUIRED_START_DATE BETWEEN
(trunc(to_date({?Month}, 'yyyy-mm-dd'),'month')
AND
last_day({?Month}))

1 个答案:

答案 0 :(得分:2)

你的前提是错的;它在SQL Developer中不起作用。如果您复制并粘贴查询并将{?Month}替换为'2015-01-01',则会收到相同的ORA-00907错误,该错误在第14行第1列报告,它自己就是AND

此:

BETWEEN
(trunc(to_date({?Month}, 'yyyy-mm-dd'),'month')
AND
last_day({?Month}))

将括号放在错误的位置 - 您尝试执行between (x and y)并且没有正确的语法。它应该是:

BETWEEN
trunc(to_date({?Month}, 'yyyy-mm-dd'),'month')
AND
last_day({?Month})

在工会的两半。

(另外,可能相关的问题:Crystal Reports - Oracle 01861 Error这个问题中的代码仍然不一致地处理参数 - 有时作为日期,有时作为字符串 - 所以它'依赖NLS设置按预期工作。)