• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Like statement for int column?

 
Hrishikesh Ghatnekar
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
 
Aman Verma
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • 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'.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic