java.persistence.Query中的函數CreateQuery(string)返回與我所請求的不同的查詢。JPA2 CreateQuery SQL服務器方言
我的輸入字符串的函數是:
from Underlying where (SUBSTRING(ticker, (charindex('.', ticker) + 1), (len(ticker) - charindex('.', ticker))) in (:exchanges) order by ticker
當我呼籲查詢getResultList(),我看到我日誌中的SQL語句:
Hibernate: select underlying0_.id as id63_, underlying0_.updated_date as updated2_63_, underlying0_.updated_user as updated3_63_, underlying0_.version as version63_, underlying0_.adr as adr63_, underlying0_.desk as desk63_, underlying0_.enabled as enabled63_, underlying0_.forward_start_enabled as forward8_63_, underlying0_.ticker as ticker63_, underlying0_.vol_shift_type as vol10_63_ from underlyings underlying0_ where (substring(underlying0_.ticker, charindex('.', underlying0_.ticker)+1) in (?)) order by underlying0_.ticker
這查詢不一個有效的SQL Server 2008的查詢和預期,我收到了一個錯誤:
SQL Error: 174, SQLState: S0001 The substring function requires 3 argument(s).
任何一個知道是怎麼回事Ø在這裏?
僅供參考,我曾嘗試以下兩種方言1)org.hibernate.dialect.SQLServer2008Dialect,和2)org.hibernate.dialect.SQLServer2008Dialect
您可以嘗試LENGTH(ticker)而不是len(ticker)。 – Gayathri
感謝您對Gayathri的回覆,我試着用LENGTH替換LEN,但是,我得到了相同的結果,即在我的輸入中3個參數被轉換爲2個參數,如日誌條目中所示。 –
我想你錯過了一個右括號。 – Gayathri