我发现PARSENAME函数是订购存储在数据库中的IP地址的不错选择。 这里有一个例子。
我的问题是我在xml映射文件中使用Hibernate和命名查询,我试图避免使用

session.createSQLQuery(..) 

函数。结果, 我想知道是否存在任何用于HQL查询的PARSENAME等效函数。我正在寻找它,找不到任何东西。
非常感谢。

有帮助吗?

解决方案

我没有发现任何相关内容。
最后,我执行了以下ORDER BY子句以数字方式排序IP地址(我找到了解决方案这里):

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)    

其他提示

对您的方言进行子类化并使用RegisterFunction()使PARSENAME可用于HQL查询。 RegisterFunction记录不完整,但有

scroll top