2

I have a condition part of my query as follows:

...
where foo.bar like '%:%'

The query would execute but with no result. I think it's because of the colon since it is a reserved char in HQL. So how can I escape it without sending the : as a parameter to my query?

I have already used '%\:%' and '%\\\\:%' with no success.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Nerssi
  • 53
  • 6
  • Try this [:] peraphs depends by DBMS – Joe Taras Sep 04 '13 at 13:32
  • Show this: http://stackoverflow.com/questions/3006524/how-to-escape-wildcard-characters-in-like-clause-in-hql – Joe Taras Sep 04 '13 at 13:38
  • Are you sure you have a `foo.bar` containing a `:` in your table? I would expect this query to execute fine and it seems it does. If there was a problem with this character, it woul dprobably throw an exception instead of running. Turn SQL logging on and see what SQL query is being executed. – JB Nizet Sep 04 '13 at 14:02
  • bar is actually the subject of an email. assume the subject is "FWD: test", if I put 'FWD' or 'test' between %s I will have the result but with colon there will be no output. – Nerssi Sep 04 '13 at 14:05
  • I found a solution: q=q.replaceAll(":","'||unistr('\\\\003A')||'"); – Nerssi Sep 04 '13 at 14:13

1 Answers1

-1

I found a solution:

q=q.replaceAll(":","'||unistr('\\\\003A')||'");
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Nerssi
  • 53
  • 6