Java
ibatis 정규식 에러
수유산장
2021. 2. 15. 19:50
select count(*) as cnt
from (
select REGEXP_REPLACE(REPLACE('.'||'192.168.100.55', '.', '.00'), '([^.]{3}(\.|$))|.', '\1') as ip
, REGEXP_REPLACE(REPLACE('.'||'192.168.100.51', '.', '.00'), '([^.]{3}(\.|$))|.', '\1') as ip_start
, REGEXP_REPLACE(REPLACE('.'||'192.168.100.56', '.', '.00'), '([^.]{3}(\.|$))|.', '\1') as ip_end
from dual
) where ip between ip_start and ip_end
이런 정규식을 ibatis에서 사용시 아래와 같은 에러가 났다.
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
또는
The error occurred while preparing the mapped statement for execution.
토드나 쿼리창에서는 잘 돌아가는 쿼리인데..
곰곰히 생각해보니
문장을 맵핑해서 준비하는데 에러가 난다.... prepare statement 로 만드는데 에러가 난다는 말 같다.
이유는 간단하다.
ibatis에서는 #변수#, $변수$ 를 이용해서 변수를 맵핑한다.
정규식에 $가 들어가 있으니 에러가 난것이다.
해결법은.... 역시 간단하다.
$$를 두번 써주면 된다.