GrandPa
GrandPa

Reputation: 504

How to use wildcard character(%) search on java.lang.Long value

I have been trying to fire a query for wild card search on an Integer value in a database. It is giving an exception.

select * from tcotet A  where  A.icont like '%7187%'

Here icont is integer in the database, and in the java class file it has been mapped to a Long value.

Is there any alternate way to use wild card search on an integer value?

Upvotes: 0

Views: 773

Answers (1)

Étienne Miret
Étienne Miret

Reputation: 6650

As Kon said, you just need to cast the integer to a string. In DB2 SQL, you whould do it like this:

select * from tcotet A where cast(A.icont as char(12)) like '%7187%'

Note that (oddly), integer cannot be cast to varchar, so you need to use the char type.

Upvotes: 1

Related Questions