简体   繁体   English

GRAILS使用to_char命名查询

[英]GRAILS named query with to_char

I am looking to query the matching records based on input number(say 56). 我希望根据输入数量(比如56)查询匹配的记录。 The type of the column in ORACLE DB is Long. ORACLE DB中列的类型为Long。 Expecting all matching records has the numbers for ex - 156, 567, 12356..etc. 期望所有匹配记录的数字为ex-156,567,12356..etc。 Is it possible to write a named query in GRAILS for above ?. 是否可以在GRAILS中为上面写一个命名查询? Is there any other way out ? 还有其他出路吗?

If you want to use database functions in your named queries, you can use the sqlRestriction clause. 如果要在命名查询中使用数据库函数,可以使用sqlRestriction子句。 Note that the syntax must match you table and not domain class, so considering: 请注意,语法必须与您的表匹配,而不是与域类匹配,因此请考虑:

class MyDomain {
  Date myField
}

Your restriction can be: 您的限制可以是:

def namedQueries = {
  someQuery {
    sqlRestriction("to_char(my_field, 'dd/mm/yyyy') = '25/07/2013'")
  }
}

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

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