比如Oracle用escape函数表示转义with t as (select 'abc' a from dual union all select 'a%c' a from dual)
select * from t where a like 'a~%c' escape'~';想查询%,就在%前面加~,代表这是个百分号字符,而不是通配符。
直接写sql,我也会写,就像楼上写的那样,用转义字符 select * from t where a like 'a~%c' escape'~'; 但是在ibatis 中如何实现? 对于参数中带百分号的条件,难道动态先拼串,如下: name = 'a~%c' escape'~' select * from t where a like %$name$%
name = "%~%%" select * from t where a like #name# escape'~'有什么问题吗你写
<select id="selectBlogsLike" parameterType="Blog" resultType="Blog"> <bind name="pattern" value="'%' + _parameter.getTitle() + '%'" /> SELECT * FROM BLOG WHERE title LIKE #{pattern} </select>
union all
select 'a%c' a from dual)
select * from t where a like 'a~%c' escape'~';想查询%,就在%前面加~,代表这是个百分号字符,而不是通配符。
select * from t where a like 'a~%c' escape'~';
但是在ibatis 中如何实现? 对于参数中带百分号的条件,难道动态先拼串,如下:
name = 'a~%c' escape'~'
select * from t where a like %$name$%
name = "%~%%"
select * from t where a like #name# escape'~'有什么问题吗你写
<bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
SELECT * FROM BLOG
WHERE title LIKE #{pattern}
</select>