SQL模糊查詢報(bào):ORA-00909:參數(shù)個(gè)數(shù)無(wú)效問(wèn)題的解決
用oracle數(shù)據(jù)庫(kù)進(jìn)行模糊查詢時(shí),
控制臺(tái)報(bào)錯(cuò)如下圖所示:
原因是因?yàn)榍玫奶?,語(yǔ)法寫錯(cuò)了
正確的寫法是
pd.code like concat(concat('%',#{keyword}),'%')
java.sql.SQLSyntaxErrorException: ORA-00909: 參數(shù)個(gè)數(shù)無(wú)效
用MyBatis進(jìn)行多參數(shù)模糊查詢的時(shí)候遇到這個(gè)異常,看了下打印日志,發(fā)現(xiàn)異常出在預(yù)編譯之后,插入實(shí)參的時(shí)候。
==> 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ù)個(gè)數(shù)無(wú)效。檢查了下SQL語(yǔ)句
select role_id, role_name, note from t_role where role_name like concat('%', ?, '%') and note like concat('%', ?, '%')
發(fā)現(xiàn)問(wèn)題出現(xiàn)在concat上,concat是連接兩個(gè)字符串的函數(shù),這里連接了三個(gè),把SQL改成兩個(gè)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é)
運(yùn)行成功啦!以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家!
相關(guān)文章
mysql啟動(dòng)錯(cuò)誤之mysql啟動(dòng)報(bào)1067錯(cuò)誤解決方法
MYSQL啟動(dòng)報(bào)1067錯(cuò)誤,系統(tǒng)日志中是“服務(wù) mysql 意外停止” Mysql日志中則是:Plugin 'FEDERATED' is disabled,下面給出解決方法2014-02-02MySQL在grant時(shí)報(bào)錯(cuò)ERROR?1064?(42000)的原因及解決方法
網(wǎng)上查到的grant方式大多會(huì)報(bào)錯(cuò),主要原因是MySQL版本8.0后不能再使用原來(lái)的方式,這篇文章主要介紹了MySQL在grant時(shí)報(bào)錯(cuò)ERROR?1064?(42000),需要的朋友可以參考下2022-08-08MySQL中count(distinct?col...)組合使用的注意要點(diǎn)詳解
@count()是一個(gè)聚合函數(shù),返回指定匹配條件的行數(shù),開發(fā)中常用來(lái)統(tǒng)計(jì)表中數(shù)據(jù)、全部數(shù)據(jù)、不為null數(shù)據(jù)或者去重?cái)?shù)據(jù),這篇文章主要給大家介紹了關(guān)于MySQL中count(distinct?col...)組合使用的注意要點(diǎn),需要的朋友可以參考下2024-08-08Mysql 5.6 "隱式轉(zhuǎn)換"導(dǎo)致的索引失效和數(shù)據(jù)不準(zhǔn)確的問(wèn)題
這篇文章主要介紹了Mysql 5.6 “隱式轉(zhuǎn)換”導(dǎo)致的索引失效和數(shù)據(jù)不準(zhǔn)確的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12