【NUMBER】有關Oracle NUMBER型別定義中precision和scale的測試和總結
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 --
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle的number資料型別Oracle資料型別
- ORACLE NUMBER資料型別Oracle資料型別
- Oracle中rownum和row_number()Oracle
- [20191001]關於oracle number型別的一些疑惑.txtOracle型別
- 10_深入解析Oracle number資料型別及os層number解析工具分享Oracle資料型別
- 淺析number型別的值型別
- [20190930]oracle raw型別轉化number指令碼.txtOracle型別指令碼
- [20190930]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191003]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- [20191013]oracle number型別儲存轉化指令碼.txtOracle型別指令碼
- JS中其他資料型別轉為number資料型別的方法JS資料型別
- LeetCode Palindrome Number(009)解法總結LeetCode
- Java Number和Math 類Java
- JS -- number資料型別詳解JS資料型別
- Js中的NumberJS
- vue中自定義指令,限制input值為number和小數點的位數Vue
- jsp頁面number型別自動轉為String型別JS型別
- Oracle實驗(03):number的使用Oracle
- LeetCode Letter Combinations of a Phone Number(017)解法總結LeetCode
- How Oracle Store Number internal(zt)Oracle
- 面試題總結:Queue 中 poll()和 remove()有什麼區別?面試題REM
- Python技術之Number資料型別介紹Python資料型別
- javaScript中Number數字型別方法入門JavaScript型別
- 自己挖的坑自己填--Mybatis mapper檔案if標籤中number型別及String型別的坑MyBatisAPP型別
- 【NUMBER】Oracle資料庫最佳化之理解NUMBER儲存機制Oracle資料庫
- 關於Python Number 相關的知識!Python
- 軟體確認測試、系統測試和驗收測試有什麼區別和關係?
- 關於mysql中欄位定義的型別int、tinyint區別MySql型別
- JS中的資料型別轉換:String轉換成Number的3種方法JS資料型別
- 認真一點學 Go:12. 自定義型別和結構體 - 定義Go型別結構體
- 關於筆試和麵試的反思總結筆試
- Hive中row_number()、dense_rank()、rank()的區別Hive
- js中==和===的區別以及總結JS
- Oracle當number型別超過一定長度直方圖限制導致SQL執行計劃錯誤Oracle型別直方圖SQL
- 關於 Go 中 Map 型別和 Slice 型別的傳遞Go型別
- APP測試中IOS和Android的區別,有哪些注意點?APPiOSAndroid
- JavaScript之number型別的數值轉換成某某進位制JavaScript型別
- JavaScript Number()JavaScript
- TypeScript中 typeof ArrayInstance[number] 剖析TypeScript