用oracle數(shù)據(jù)庫進(jìn)行模糊查詢時,
控制臺報錯如下圖所示:
![](/d/20211017/c41c62a02abf32330c3754ba7a85a640.gif)
原因是因為敲的太快,語法寫錯了
正確的寫法是
pd.code like concat(concat('%',#{keyword}),'%')
java.sql.SQLSyntaxErrorException: ORA-00909: 參數(shù)個數(shù)無效
用MyBatis進(jìn)行多參數(shù)模糊查詢的時候遇到這個異常,看了下打印日志,發(fā)現(xiàn)異常出在預(yù)編譯之后,插入實參的時候。
==> Preparing: select role_id, role_name, note from t_role where role_name like concat('%', ?, '%') and note like concat('%', ?, '%')
2018-12-13 20:24:28,567 DEBUG [com.ss.learn.chapter3.mapper.RoleMapper.getRolesByIdAndNote] - ==> Parameters: 1(String), 1(String)
異常提示:參數(shù)個數(shù)無效。檢查了下SQL語句
select role_id, role_name, note from t_role
where role_name like concat('%', ?, '%') and note like concat('%', ?, '%')
發(fā)現(xiàn)問題出現(xiàn)在concat上,concat是連接兩個字符串的函數(shù),這里連接了三個,把SQL改成兩個concat嵌套的
select id="getRolesByIdAndNote" parameterType="map" resultType="role">
select role_id, role_name, note from t_role
where role_name like concat(concat('%', #{roleName}), '%')
and note like concat(concat('%', #{note}), '%')
/select>
總結(jié)
運行成功啦!以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家!
您可能感興趣的文章:- 有關(guān)SQL模糊查詢
- SqlServer中模糊查詢對于特殊字符的處理方法
- SQL Server模糊查詢的常見方法總結(jié)
- Mybatis使用MySQL模糊查詢時輸入中文檢索不到結(jié)果怎么辦