Tuesday, June 8, 2010

CAST function to convert string to numeric value

Through the SQL statements, we learn to handle strings as numeric values:

create table pippo (id varchar(50));
delete from pippo;
insert into pippo values ('1223430');
insert into pippo values ('300030');

DB2
select * from pippo order by integer(id);

MySQL
select * from pippo order by cast(id as decimal);

Oracle
select * from pippo order by to_number(id);

No comments:

Post a Comment