• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

grep like "where clause"?

 
jeroen dijkmeijer
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've got a table with many rows, one column is called code and is mapped to myClass.code. the code is a free format and may contain anything. Some codes however have a special format which is C\d{4}, a "C" followed by 4 digits. Is there a way in Hibernate to retrieve a list with only those codes? Or should I just do something like "like 'U%'" and iterate over the resultSet to eliminate the false selected?

regards,
Jeroen.
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, I think you can do all this with combining string functions
like "third character in (0,1,...9)" etc., although such a WHERE clause is
going to be quite long.
It may be that your database supports an easier way, such as regular expressions.
 
jeroen dijkmeijer
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For oracle (9i) it worked with
<from B b where translate( b.c, '1234567890','##########') = 'C####' and book.n = :n">
jeroen.

[ November 26, 2007: Message edited by: jeroen dijkmeijer ]
[ November 26, 2007: Message edited by: jeroen dijkmeijer ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic