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&CSS&JS compatibility tree (IE, Firefox, Chrome)

What is a tree in web design? Simply put, clicking...

How webpack implements static resource caching

Table of contents introduction Distinguish betwee...

Use a diagram to explain what Web2.0 is

Nowadays we often talk about Web2.0, so what is W...

Front-end state management (Part 1)

Table of contents 1. What is front-end state mana...

Detailed process of installing and configuring MySQL and Navicat prenium

Prerequisite: Mac, zsh installed, mysql downloade...

W3C Tutorial (2): W3C Programs

The W3C standardization process is divided into 7...

Quickly learn MySQL basics

Table of contents Understanding SQL Understanding...

How does MySQL achieve master-slave synchronization?

Master-slave synchronization, also called master-...

10 key differences between HTML5 and HTML4

HTML5 is the next version of the HTML standard. M...

Introduction to query commands for MySQL stored procedures

As shown below: select name from mysql.proc where...

How to solve the problem of forgetting the root password of Mysql on Mac

I haven't used mysql on my computer for a lon...

WeChat applet implements jigsaw puzzle game

This article shares the specific code for impleme...

How to quickly install Nginx in Linux

Table of contents What is nginx 1. Download the r...