2009-11-30 172 views
0

我发现PARSENAME函数是订购存储在数据库中的IP地址的好选择。 Here有一个例子。
我的问题是,我使用Hibernate在一个XML映射文件命名查询和我试图避免使用HQL'parsename'相当于

session.createSQLQuery(..) 

功能。
我想知道是否存在任何与HQL查询相同的PARSENAME函数。我正在寻找它并找不到任何东西。
非常感谢。

回答

1

我没有找到任何相关的。
最后,我执行以下ORDER BY子句来订购数字方式的IP地址(我找到了解决办法here):

order by cast(substring(host.ip, 1, locate('.', host.ip) - 1) as integer), 
       cast(substring(host.ip, locate('.', host.ip) + 1, locate('.', host.ip, locate('.', host.ip) + 1) - locate('.', host.ip) - 1) as integer), 
       cast(substring(host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1, locate('.', host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1) - locate('.', host.ip, locate('.', host.ip) + 1) - 1) as integer), 
       cast(substring(host.ip, locate('.', host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1) + 1, 3) as integer)  
0

子类的话,并使用RegisterFunction()使PARSENAME提供给HQL查询。 RegisterFunction没有很好的记录,但有plenty of examples on the web。我不确定你可以用订购的结果。