Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6587713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:57:11+00:00 2026-05-25T16:57:11+00:00

In MyBatis , you mark the places where parameters should be inserted into your

  • 0

In MyBatis, you mark the places where parameters should be inserted into your SQL like so:

SELECT * FROM Person WHERE id = #{id}

This syntax activates proper escaping etc to avoid, among other things, SQL injection attacks. If you have trusted input and want to skip escaping, you can insert the parameters verbatim:

SELECT * FROM {tableName} WHERE id = #{id}

Now, I want to do a LIKE search on unsafe input, so what I want to do is this:

SELECT * FROM Person WHERE name LIKE #{beginningOfName} || ‘%’

Unfortunately, however, important DB servers don’t support the || syntax for concatenation:

MSSQL – Breaks the standard by using the ‘+’ operator instead of ‘||’.

…

MySQL – Badly breaks the standard by redefining || to mean OR.

So, I could do either

SELECT * FROM Person WHERE name LIKE CONCAT(#{beginningOfName}, ‘%’)

and be confined to, in this case, MySQL, or I could do

SELECT * FROM Person WHERE name LIKE ‘{beginningOfName}%’

and would have to sanitize input myself.

Is there a more elegant solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:57:12+00:00Added an answer on May 25, 2026 at 4:57 pm

    Typically this is done by adding the % to the parameter itself before passing it in, in whatever language you’re using outside of SQL. However note that either way you might still need to do an escaping step if your search term may have _ or % in it. See eg this question for background.)

    To fix the concatenation problem in general, put MySQL into ANSI sql_mode and you get proper support for the || operator, as well as correct handling of double quotes for schema names rather than string literals.

    (If you can’t do that you’d have to build a function to build the statement out of either || or CONCAT(), abstracting away the difference.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Decided to move one of my project from iBatis to MyBatis and ran into
Say I have this MYBATIS statement: <insert id=insertValue resultType=car > BEGIN TRANSACTION INSERT INTO
mybatis' homepage has this quote mybatis, the world's most popular sql mapping framework There
MyBatis migrations splits each SQL file into two sections: One for migrating forward one
From the API Doc of mybatis i can just see, that insert, delete, select
I'm new to MyBatis and my project requires me to read the data from
I'm upgrading from iBatis 2.x to myBatis 3.0.6 and I have a mapper file
I am currently migrating code from iBatis 2 to MyBatis 3. I have a
I'm setting up mybatis using annotations, and getting this helpful exception org.apache.ibatis.binding.BindingException: Type interface
I want to Pass 'Map' to an PL/SQL Stored Procedure via Spring Mybatis Mapper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.