用oracle數(shù)據(jù)庫進行模糊查詢時,
原因是因為敲的太快,語法寫錯了
正確的寫法是
pd.code like concat(concat('%',#{keyword}),'%')
java.sql.SQLSyntaxErrorException: ORA-00909: 參數(shù)個數(shù)無效
用MyBatis進行多參數(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>
運行成功啦!以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家!