SQL模糊查詢報:ORA-00909:參數(shù)個數(shù)無效問題的解決
用oracle數(shù)據(jù)庫進行模糊查詢時,
控制臺報錯如下圖所示:
原因是因為敲的太快,語法寫錯了
正確的寫法是
pd.code like concat(concat('%',#{keyword}),'%')
java.sql.SQLSyntaxErrorException: ORA-00909: 參數(shù)個數(shù)無效
用MyBatis進行多參數(shù)模糊查詢的時候遇到這個異常,看了下打印日志,發(fā)現(xiàn)異常出在預編譯之后,插入實參的時候。
==> 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)文章
MySQL在grant時報錯ERROR?1064?(42000)的原因及解決方法
網(wǎng)上查到的grant方式大多會報錯,主要原因是MySQL版本8.0后不能再使用原來的方式,這篇文章主要介紹了MySQL在grant時報錯ERROR?1064?(42000),需要的朋友可以參考下2022-08-08MySQL中count(distinct?col...)組合使用的注意要點詳解
@count()是一個聚合函數(shù),返回指定匹配條件的行數(shù),開發(fā)中常用來統(tǒng)計表中數(shù)據(jù)、全部數(shù)據(jù)、不為null數(shù)據(jù)或者去重數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于MySQL中count(distinct?col...)組合使用的注意要點,需要的朋友可以參考下2024-08-08Mysql 5.6 "隱式轉(zhuǎn)換"導致的索引失效和數(shù)據(jù)不準確的問題
這篇文章主要介紹了Mysql 5.6 “隱式轉(zhuǎn)換”導致的索引失效和數(shù)據(jù)不準確的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12