[20150503]關於oracle的number型別.txt
[20150503]關於oracle的number型別.txt
--節前的事情,別人建表使用number型別,本來想定義成number(10,2),結果少輸入0,變成number(1,2).
--在我的記憶裡,好像前面的數值應該大於後面的精度的,沒想到這樣竟然可以透過,自己感到很奇怪!
--測試下來,才知道自己oracle基本的東西都不是很清楚.
1.首先提到我以前寫的一篇blog:
[20140823]在sqlplus使用copy注意.txt
http://blog.itpub.net/267265/viewspace-1257036/
在這篇blog中我提到定義number型別最好包含精度和小數點位數.
2.接著看看上面的定義會如何?
--看看oracle 文件:
NUMBER Data Type
The NUMBER data type stores zero as well as positive and negative fixed numbers with
absolute values from 1.0 x 10^-130 to but not including 1.0 x 10^126
. If you specify an arithmetic expression whose value has an absolute value greater than or equal to 1.0 x 10^126
, then Oracle returns an error. Each NUMBER value requires from 1 to 22 bytes.
Specify a fixed-point number using the following form:
NUMBER(p,s)
■ p is the precision, or the maximum number of significant decimal digits, where the
most significant digit is the left-most nonzero digit, and the least significant digit is
the right-most known digit. Oracle guarantees the portability of numbers with
precision of up to 20 base-100 digits, which is equivalent to 39 or 40 decimal digits
depending on the position of the decimal point.
■ s is the scale, or the number of digits from the decimal point to the least significant
digit. The scale can range from -84 to 127.
– Positive scale is the number of significant digits to the right of the decimal
point to and including the least significant digit.
– Negative scale is the number of significant digits to the left of the decimal
point, to but not including the least significant digit. For negative scale the
least significant digit is on the left side of the decimal point, because the actual
data is rounded to the specified number of places to the left of the decimal
point. For example, a specification of (10,-2) means to round to hundreds.
Scale can be greater than precision, most commonly when e notation is used. When
scale is greater than precision, the precision specifies the maximum number of
significant digits to the right of the decimal point. For example, a column defined as
NUMBER(4,5) requires a zero for the first digit after the decimal point and rounds all
values past the fifth digit after the decimal point.
--文件明確提到Scale can be greater than precision.
It is good practice to specify the scale and precision of a fixed-point number column
for extra integrity checking on input. Specifying scale and precision does not force all
values to a fixed length. If a value exceeds the precision, then Oracle returns an error. If
a value exceeds the scale, then Oracle rounds it.
Specify an integer using the following form:
NUMBER(p)
This represents a fixed-point number with precision p and scale 0 and is equivalent to
NUMBER(p,0).
Specify a floating-point number using the following form:
NUMBER
The absence of precision and scale designators specifies the maximum range and
precision for an Oracle number.
--測試:
SCOTT@test01p> create table t1 ( a number(1,2));
Table created.
SCOTT@test01p> insert into t1 values(0.10);
insert into t1 values(0.10)
*
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column
SCOTT@test01p> insert into t1 values(0.01);
1 row created.
SCOTT@test01p> insert into t1 values(0.091);
1 row created.
SCOTT@test01p> select * from t1;
A
----------
.01
.09
--很明顯這樣定義僅僅能插入0.01-0.09(當然沒有包括負數),再過來看就很容易裡面前面的定義.精度1表示僅僅最後1位有數值(把值*100).
--假如我定義number(2,2)表示的範圍就是0.01-0.99 (不包括負數).
SCOTT@test01p> create table t2 ( a number(2,2));
Table created.
SCOTT@test01p> insert into t2 values(0.99);
1 row created.
SCOTT@test01p> insert into t2 values(0.01);
1 row created.
SCOTT@test01p> insert into t2 values(1.00);
insert into t2 values(1.00)
*
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column
SCOTT@test01p> insert into t2 values(-0.99);
1 row created.
SCOTT@test01p> select * from t2;
A
----------
.99
.01
-.99
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1621288/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20191001]關於oracle number型別的一些疑惑.txtOracle型別
- [20190930]oracle raw型別轉化number指令碼.txtOracle型別指令碼
- [20190930]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191003]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191013]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- Oracle的number資料型別Oracle資料型別
- ORACLE NUMBER資料型別Oracle資料型別
- 10_深入解析Oracle number資料型別及os層number解析工具分享Oracle資料型別
- [20191219]oracle timestamp資料型別的儲存.txtOracle資料型別
- 淺析number型別的值型別
- [20241009]oracle timestamp with time zone資料型別的儲存.txtOracle資料型別
- 關於Python Number 相關的知識!Python
- [20201207]關於ORACLE IMU的一些疑問.txtOracle
- 關於 Go 中 Map 型別和 Slice 型別的傳遞Go型別
- [20190311]關於oracle物理與邏輯壞塊.txtOracle
- 關於 PHP 的資料型別 (一)PHP資料型別
- 關於 PHP 的資料型別 (二)PHP資料型別
- 關於 PHP 的資料型別 (三)PHP資料型別
- jsp頁面number型別自動轉為String型別JS型別
- JS -- number資料型別詳解JS資料型別
- JS中其他資料型別轉為number資料型別的方法JS資料型別
- [20191202]關於oracle例項是否使用hugepages問題.txtOracle
- 關於結構體型別的學習結構體型別
- 幽默:關於型別的觀點演變型別
- 關於不完全型別的認識型別
- [20180917]關於分析函式的range與rows的區別.txt函式
- [20190612]NULL的資料型別.txtNull資料型別
- ORACLE日期型別Oracle型別
- 關於Java和C#的型別對比JavaC#型別
- 關於Mapreduce Text型別賦值的錯誤型別賦值
- 關於synchronized的理解,共有兩種型別的鎖:synchronized型別
- [20200512]oracle的事務隔離級別.txtOracle
- [20191204]關於oracle例項是否使用hugepages問題2.txtOracle
- Oracle資料型別對應Java型別Oracle資料型別Java
- ORACLE物件型別表Oracle物件型別
- Oracle 資料型別Oracle資料型別
- 關於int型別數值的運算問題型別
- Oracle實驗(03):number的使用Oracle
- 關於mysql中欄位定義的型別int、tinyint區別MySql型別