Question: I
have column value of 00000000399 and I need to convert this to a
floating point number like 3.99. How do I convert a number
column to a floating point number?
Answer: Oracle has several ways to convert
a number (or a string!) to a floating pint number. The ideal
of a floating point number is a DISPLAY issue and you convert it at
select time. The Oracle documentation shows these examples for
table column datatypes and displayed values:
Oracle number data types and floating points
(Source: Oracle Corporation Documentation)
Oracle string to number conversion:
Consider a table with a character string, containing a number:
create table
mytab
(numcol varchar2);
insert into mytab values
('12345.67');
In SQL*Plus, Oracle will
automatically convert a string to a floating point number (called
"implicit conversion") or a number data type to a float display using the "column" and "format" clauses:
column numcol format
9999.99
select to_number(numcol) from mytab;
You can also convert a string datatype to a floating point
number using Oracle built-in functions:
select
to_binary_double(numcol) binary_double,
to_binary_float(numcol) binary_float_number,
to_number(numcol) number_datatype
from mytab;
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|