SQL fuzzy query report: ORA-00909: invalid number of parameters solution

SQL fuzzy query report: ORA-00909: invalid number of parameters solution

When using Oracle database for fuzzy query,

The console error is shown in the following figure:

The reason is that I typed too fast and the grammar was wrong.

The correct way to write it is

pd.code like concat(concat('%',#{keyword}),'%')

java.sql.SQLSyntaxErrorException: ORA-00909: invalid number of parameters

I encountered this exception when using MyBatis for multi-parameter fuzzy query. I looked at the print log and found that the exception occurred after pre-compilation and when inserting actual parameters.

==> 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)

Exception message: The number of parameters is invalid. Checked the SQL statement

select role_id, role_name, note from t_role
where role_name like concat('%', ?, '%') and note like concat('%', ?, '%')

I found that the problem occurred in concat. concat is a function that connects two strings. Here, three are connected. Change the SQL to two nested concats.

<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>

Summarize

The operation was successful! The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM!

You may also be interested in:
  • About SQL fuzzy query
  • How to handle special characters in fuzzy query in SqlServer
  • Summary of common methods of SQL Server fuzzy query
  • What to do if Mybatis cannot retrieve results when entering Chinese characters using MySQL fuzzy query

<<:  Docker builds Redis5.0 and mounts data

>>:  Detailed explanation of flex layout in CSS

Recommend

【HTML element】Detailed explanation of tag text

1. Use basic text elements to mark up content Fir...

MySQL database index order by sorting detailed explanation

Table of contents The cause of the incident Anato...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Realizing tree-shaped secondary tables based on angular

First look at the effect: Code: 1.html <div cl...

Solution for mobile browsers not supporting position: fix

The specific method is as follows: CSS Code Copy ...

Native js to realize bouncing ball

On a whim, I wrote a case study of a small ball b...

JS gets the position of the nth occurrence of a specified string in a string

Learn about similar methods for getting character...

JavaScript using Ckeditor + Ckfinder file upload case detailed explanation

Table of contents 1. Preparation 2. Decompression...

Detailed examples of replace and replace into in MySQL into_Mysql

MySQL replace and replace into are both frequentl...

Listen directive example analysis in nginx

Plot Review In the previous article, we analyzed ...

Mysql implementation of full-text search and keyword scoring method example

1. Introduction Today a colleague asked me how to...

JS realizes the effect of Baidu News navigation bar

This article shares the specific code of JS to ac...

How to convert MySQL horizontally to vertically and vertically to horizontally

Initialize Data DROP TABLE IF EXISTS `test_01`; C...

How to import SQL files in Navicat Premium

I started working on my final project today, but ...