【NUMBER】有關Oracle NUMBER型別定義中precision和scale的測試和總結

secooler發表於2010-09-11
NUMBER資料型別的定義格式是:NUMBER(p,s)。本文對定義中的p(precision)和s(scale)做一個解釋和總結。

1.官方文件中有關NUMBER資料型別的描述
p is the precision, or the total 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.

2.關於NUMBER資料型別的測試
create table test ( a number(1,3));

insert into test values(0.12);
                        *
第 1 行出現錯誤:
ORA-01438: 值大於此列指定的允許精度


insert into test values(0.012);

已建立 1 行。

insert into test values(0.0125);

已建立 1 行。

select * from test;

         A
----------
      .012
      .013

3.小結
1)整數部分長度>p-s時,報錯;
2)小數部分長度>s時,舍入;
3)s為負數時,對小數點左邊的s數字進行舍入;
4)當s>p時,p表示小數後第s位向左最多可以有多少位數字,如果大於p則報錯,小數點後s位向右的數字被舍入.

Good luck.

secooler
10.09.11

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-557312/,如需轉載,請註明出處,否則將追究法律責任。

相關文章