简体   繁体   English

从SQL到HQL的“开始于”和“按优先级连接”

[英]SQL to HQL 'start with' and 'Connect by Prior'

I need to find a way to get the ids starting with 11, in sql is with 'start with' and 'Connect by prior' but in HQL, how can I do that?, if there is a better way in grails, the help would be great, thanks! 我需要找到一种方法来获取以11开头的id,在sql中是使用“ start with”和“按优先顺序连接”,但是在HQL中,我该怎么做?如果在grails中有更好的方法,则可以太好了,谢谢!

(Updated: Sorry, I didn't write the other command which is: 'connect by prior') (更新:抱歉,我没有写另一个命令:“按先连接”)

Assuming the ID is a string, why not simply use a like clause: 假设ID是一个字符串,为什么不简单使用like子句:

where id like '11%'

Assuming it's not a string, you could cast it to a string: 假设它不是字符串,则可以将其转换为字符串:

where cast(id as STRING) like '11%'

or 要么

where str(id) like '11%'

如果您的意思是查询ID大于或等于11的记录,那么例如,如果您有一个Books表,则HQL为

def books = Books.executeQuery("SELECT b from Books b WHERE id >= 11")

Recursive SQL queries are non-standard so HQL does not support them (although I found a paper that appears to propose and prototype adding support). 递归SQL查询是非标准的,因此HQL不支持它们(尽管我发现了一篇似乎提出并提供支持原型的论文 )。 To do them you'll need to stick with SQL. 为此,您需要坚持使用SQL。 Here's a similar question . 这是一个类似的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM