Search code examples
mysqlgrailsgrails-orm

How to query in database to check if Phrase this character exist or not in groovy


I am new in groovy. I am trying to make query in database that if this character for example "099900" contain in database. in general I save in database the string like : "9898989898" but I want to make query that give me all result who's character begin with "98". Any idea?

class AccountNumber {


    static reportable = [columns: ['id', 'number']]

    static mapping = {
        cache false
        table 'accountNumber'
        version false
        id generator: 'identity', column: 'id'
    }
    Integer id;
    String number;

}

Solution

  • The GRAILS way of doing it:

    def accounts = AccountNumber.findByNumberLike("98%")
    
    // Now you can do something with the returned accounts
    // For example:
    accounts.each { account ->
        println "ID: ${account.id}, NUMBER: ${account.number}"
    }