0
我試圖從數據庫中查詢數據,但我想刪除特定列的最後三個字符。該SQL是有效的SQL SERVER,但是當我把它進入休眠的語法,日食顯示爲標題,SQL上下文如下:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的標記:左第1行第24列
String sql = "select distinct d.code,LEFT(d.VILLAGE, (LEN(d.VILLAGE)-3)) as village_name from DistrictInfo d where d.county=:region and d.town=:town and LEN(d.VILLAGE) !=0";
Query q = session.createQuery(sql);
q.setString("region", region);
q.setString("town", town)
的特例如下:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LEFT near line 1, column 24 [select distinct d.code,LEFT(d.VILLAGE, (LEN(d.VILLAGE)-3)) as village_name from org.nergis.orm.model.DistrictInfo d where d.county=:region and d.town=:town and LEN(d.VILLAGE) !=0]
請問LEFT()
導致異常?我怎樣才能做到這一點?
我通過使用Hibernate createSQLQuery解決了異常 – Huang