Search notes:

Oracle SQL: Implict data type conversion

create table tq84_A (
   num  number
);

create table tq84_B (
   txt  varchar2( 3)
);

insert into tq84_A values (   0 );
insert into tq84_A values (   1 );

insert into TQ84_B values (  '0');
insert into TQ84_B values ('000');
insert into TQ84_B values (  '1');
insert into TQ84_B values ('001');

select
   a.num,
   b.txt
from
   tq84_A a    join
   tq84_B b on a.num = b.txt;
--
--        NUM TXT
-- ---------- ---
--          0 0  
--          0 000
--          1 1  
--          1 001
   
drop table tq84_A;
drop table tq84_B;

Comparisons between numbers and varchar2's

select 1 from dual where   5   <   40 ;  /* Comparing two numbers:  true          */
select 1 from dual where  '5'  <  '40';  /* Comparing two varchar2: false         */
 
select 1 from dual where  '5'  <   40 ;  /* Varchar2 is converted to number: true */
select 1 from dual where   5   <  '40';  /* Same thing                     : true */
 
select 1 from dual where   4   < 'xxx';  /* Cannot convert varchar2 to number: ORA-01722: invalid number */

See also

Oracle data types

Index