Friends, i'm new in SQL and i can't find answer to my question
I'm trying to insert decimal number with SQL Developer (version 4, build 15), but SQL Developer automaticaly rounding my number. My test DB is OracleXE112_Win64.
Example:
CREATE TABLE salespeople
(
snum INTEGER NOT NULL PRIMARY KEY,
sname CHAR(15) NOT NULL,
city CHAR(15) NOT NULL,
comm DECIMAL
);
then
insert into SALESPEOPLE
values (1001, 'Peel', 'London', .12);
insert into SALESPEOPLE
values (1002, 'Serres', 'San Jose', .13);
insert into SALESPEOPLE
values (1004, 'Motika', 'London', .11);
insert into SALESPEOPLE
values (1007, 'Rifkin', 'Barcelona', .15);
insert into SALESPEOPLE
values (1003, 'Axelrod', 'New York', .10);
As as result i see 0 in comm column. When i'm trying to insert number 1.35 , it's rounding to 1.
Thanks
The decimal
data type needs a scale and precision. "Scale" is the number of digits after the decimal point.
When you don't specify the value for scale, then it defaults to 0 -- essentially an integer. (And precision defaults to 5.)
Typically, Oracle databases use number
instead of decimal
. But, if you want decimal
, specify the appropriate scale and precision.
Checking the Oracle documentation for DECIMAL , it says:
"If the scale is not specified, the default scale is 0. If the precision is not specified, the default precision is 5."
Precision is : "the total number of digits, both to the left and the right of the decimal point".
Scale is : "the number of digits of the fractional component".
This means that because your default scale is 0, then all numbers are rounded to an integer.
To fix this you need to specify a SCALE
for your data. Most scenarios I've seen are sufficed by DECIMAL(18,5)
and from your example queries this should be fine.
So, just change your table definition to:
CREATE TABLE salespeople
(
snum INTEGER NOT NULL PRIMARY KEY,
sname CHAR(15) NOT NULL,
city CHAR(15) NOT NULL,
comm DECIMAL(18,5)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.