• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to use Like statement for int column?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have a table which contains two columns, Emp Number and Emp Name where Emp Number is int and Emp Name is String.

I want to run a search on the same table for which I am trying to run two quaries.

1)Select * from mytable where Emp_Name LIKE �%ri%�
2)Select * from mytable where Emp_Number LIKE �%3%�


Now my problem is the first quary runs fine , but second does not.
I am getting error ->
Function LIKE invoked with wrong number or type of argument(s).


My question is is it possible to use LIKE keyword for the columns which contain int?

If no then when is the other way to do this kind of quary?


Thanks
Hrishikesh
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hrikesh,

I think We can use % to search integers from a table.
e.g on oracle 9i following queries work fine and gives expected results.

SELECT * FROM test WHERE id LIKE '3%'

SELECT * FROM test WHERE id LIKE '%3'

SELECT * FROM test WHERE id LIKE '%3%'

These queries work fine on oracle 9i but I donno abt the previous versions of oracle.

Regards,
-Rahul
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question might be better posted in the JDBC forum, where SQL questions tend to get asked. You are more likely to get a response.

That being said:


My question is is it possible to use LIKE keyword for the columns which contain int?


No (unless the emp_number column is a character data type). The LIKE operator is for character, string or clob values, not numeric values. What is "like" 3 anyway? Values near it e.g. 2 and 4? Or values including a 3 e.g 33, 333, 1903, 0.23232?

You could change Emp_number to a varchar datatype, or use a BETWEEN or IN operator, if either of those suit what you are trying to acheive.
[ May 16, 2005: Message edited by: Paul Sturrock ]
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the database, you may use a builtin function, to convert empid to a string, and perform LIKE on that string:


Consult your DB-Manual, to find out, what's the real name for 'toString'.
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!