sqloracle-databaseselectvarchar2

Oracle | Varchar2 | Number Equality | Different output


I have a table in Oracle, let's say Table1:

Column - ticketNo - NOT NULL VARCHAR2(10)

Now when I run different queries, I get different outputs, though record is present.

select * 
from Table1 
where ticketNo = '0900000106'; -- Fetches the record

select * 
from Table1 
where ticketNo = '0810087720'; -- Fetches the record

select * 
from Table1 
where ticketNo = '0050001104'; -- Fetches the record

select * 
from Table1 
where ticketNo = '3180000013'; -- Fetches the record


select * 
from Table1 
where ticketNo = '900000100'; --  Does not fetch the record

select * 
from Table1 
where ticketNo = '5889770';    -- Fetches the record

select * 
from Table1 
where ticketNo = 0900000106; -- Fetches the record

select * from Table1 where ticketNo = 0810087720; -- Fetches the record
select * from Table1 where ticketNo = 0050001104; -- Fetches the record
select * from Table1 where ticketNo = 3180000013; -- Fetches the record

select * from Table1 where ticketNo = 900000100; --  Fetches the record
select * from Table1 where ticketNo = 5889770;    -- Fetches the record

I am not able to understand why for the few records '' comparison fails.

I am using SQL Developer to query above.

Oracle IDE 17.4.1.054.0712


Solution

  • When comparing a character value with a numeric value, Oracle converts the character data to a numeric value

    For example when your compare ticketNo = 900000106 the character value '0900000106' of ticketNo is converted to number 900000106 and matches the right term of equality.