Quantcast

How to use Like Operator with (%) in MyBatis?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to use Like Operator with (%) in MyBatis?

v.sk
I want to achieve Select * from patient where last_name like '%john%'
with mybatis 3.0.

I am using the following code but somehow doesn't seam to work as
expected and gets all the records.
select * from patient where last_name like '%'|| #{lastName} ||'%'.

Anyone aware of the solution?

Regards,
Sk

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to use Like Operator with (%) in MyBatis?

Larry Meadors
That should work - turn on logging and see what the SQL being executed
looks like.

On Tue, Mar 6, 2012 at 5:23 AM, vsk <[hidden email]> wrote:

> I want to achieve Select * from patient where last_name like '%john%'
> with mybatis 3.0.
>
> I am using the following code but somehow doesn't seam to work as
> expected and gets all the records.
> select * from patient where last_name like '%'|| #{lastName} ||'%'.
>
> Anyone aware of the solution?
>
> Regards,
> Sk
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to use Like Operator with (%) in MyBatis?

Filipe Sousa
In reply to this post by v.sk
You can always call my_select_method("%" + lastName + "%")

On Tuesday, March 6, 2012 12:23:19 PM UTC, vsk wrote:
I want to achieve Select * from patient where last_name like '%john%'
with mybatis 3.0.

I am using the following code but somehow doesn't seam to work as
expected and gets all the records.
select * from patient where last_name like '%'|| #{lastName} ||'%'.

Anyone aware of the solution?

Regards,
Sk

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to use Like Operator with (%) in MyBatis?

Benoît
Alternatively add the '%' chars to your property just before calling
the mapper.


On Mar 6, 3:29 pm, Filipe Sousa <[hidden email]> wrote:

> You can always call my_select_method("%" + lastName + "%")
>
>
>
>
>
>
>
> On Tuesday, March 6, 2012 12:23:19 PM UTC, vsk wrote:
>
> > I want to achieve Select * from patient where last_name like '%john%'
> > with mybatis 3.0.
>
> > I am using the following code but somehow doesn't seam to work as
> > expected and gets all the records.
> > select * from patient where last_name like '%'|| #{lastName} ||'%'.
>
> > Anyone aware of the solution?
>
> > Regards,
> > Sk
Loading...