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

What you need to understand about MySQL locks

1. Introduction MySQL locks can be divided into g...

How to use MySQL DATEDIFF function to get the time interval between two dates

describe Returns the time interval between two da...

Zabbix monitors Linux hosts based on snmp

Preface: The Linux host is relatively easy to han...

How to view and set the mysql time zone

1. Check the database time zone show variables li...

Detailed explanation of type protection in TypeScript

Table of contents Overview Type Assertions in syn...

Implementation of local migration of docker images

I've been learning Docker recently, and I oft...

Three notification bar scrolling effects implemented with pure CSS

Preface The notification bar component is a relat...

Detailed explanation of 7 SSH command usages in Linux that you don’t know

A system administrator may manage multiple server...

uniapp implements date and time picker

This article example shares the specific code of ...

Several methods of implementing two fixed columns and one adaptive column in CSS

This article introduces several methods of implem...

Detailed explanation of the basic use of centos7 firewall in linux

1. Basic use of firewalld start up: systemctl sta...

Use Typescript configuration steps in Vue

Table of contents 1. TypeScript is introduced int...

In-depth understanding of JavaScript callback functions

Table of contents Preface Quick Review: JavaScrip...