Hibernate:期待“结束”,发现'/'SQL异常

时间:2013-04-30 07:10:29

标签: sql oracle hibernate hql case

我正在尝试运行一个如下所示的查询

SELECT INV.SKU_NUM as skuNum , ITM.REG_DES as des, ITM.DFLT_WHS_UOM as uom, CASE WHEN        ITM.BILL_QTY IS NULL THEN NULL  ELSE (CASE WHEN INV.RQST_QTY IS NULL THEN 0 ELSE INV.RQST_QTY END) / ITM.BILL_QTY END AS qty,
INV.FROM_LOC_CD as fromLocCd , INV.TO_LOC_CD as toLocCd , INV.EMP_INIT as empInit , INV.PRIORITY as priority , ITM.DES1 as des1, ITM.DES2 as des2 , ITM.VE_CD as veCd, ITM.DIV_CD as divCd , ITM.DEPT_CD as deptCd , ITM.CLASS_CD as classCd , ITM.SUBCLASS_CD as subClassCd
FROM INV_MVMT INV
LEFT OUTER JOIN  GM_SKU SKU on INV.SKU_NUM = SKU.SKU_NUM
LEFT OUTER JOIN GM_ITM ITM on SKU.ITM_CD = ITM.ITM_CD
WHERE 1=1 
and INV.STORE_CD = '<something>'

当我以HQL执行上述查询时。我收到以下错误

expecting "end", found '/'

我想使用简单的HQL执行上述查询。我不想将它作为SQL查询执行,我也不想使用Criteria。

当我在SQL开发人员或TOAD中运行它时,此查询完全正常。但是当我作为HQL执行它时不起作用。请在这里建议我做错了什么。

ANSWER
我实际上输入了错误的查询

当使用case语句时。他们必须小心逻辑和括号

我应该输入

(CASE WHEN ITM.BILL_QTY IS NULL THEN NULL  ELSE (CASE WHEN INV.RQST_QTY IS NULL THEN 0 ELSE INV.RQST_QTY/ ITM.BILL_QTY END) END) AS qty

而不是

CASE WHEN ITM.BILL_QTY IS NULL THEN NULL  ELSE (CASE WHEN INV.RQST_QTY IS NULL THEN 0 ELSE INV.RQST_QTY END) / ITM.BILL_QTY END AS qty

这解决了上述问题,但遇到了JOINS的其他问题。

0 个答案:

没有答案