Home Database Mysql Tutorial Oracle中的decimal与Number区别

Oracle中的decimal与Number区别

Jun 07, 2016 pm 05:28 PM
o

Oracle只是在语法上支持decimal类型,但是在底层实际上它就是number类型,支持decimal类型是为了能把数据从Oracle数据库移到其他

一、DECIMAL类型详细

Oracle只是在语法上支持decimal类型,但是在底层实际上它就是number类型,支持decimal类型是为了能把数据从Oracle数据库移到其他数据库中(如DB2等)。

 因为decimal在Oracle底层就是number类型,所以就当number类型使用就可以了,如果需要对这种字段类型转为char类型可以用to_char函数对其转换。

decimal类型从根本上说应该是数字类型的,因为oracle内部的数据类型,对于数字只有number类型,都当数字类型进行处理即可。decimal(8,2)代表数字总共8位长度,小数部分是2位。范围是8位,精确到小数点后2位,并四舍五入,即存6位整数,两位小数。也就是最大值可以是999999.99,可存放2位小数。Oracle中,可以使用to_char函数对数字进行转换,使它变成字符类型.

二、NUMBER类型详细

在Oracle中Number类型可以用来存储0,正负定点或者浮点数,可表示的数据范围在

1.0 * 10(-130) —— 9.9...9 * 10(125) {38个9后边带88个0}

 的数字,当Oracle中的数学表达式的值>=1.0*10(126)时,Oracle就会报错。

Number的数据声明如下:

表示

作用

说明

Number(p, s)

声明一个定点数

p(precision)为精度,s(scale)表示小数点右边的数字个数,精度最大值为38,,scale的取值范围为-84到127

Number(p)

声明一个整数

相当于Number(p, 0)

Number

声明一个浮点数

其精度为38,要注意的是scale的值没有应用,也就是说scale的指不能简单的理解为0,或者其他的数。

定点数的精度(p)和刻度(s)遵循以下规则:
 
当一个数的整数部分的长度> p-s 时,Oracle就会报错
 
当一个数的小数部分的长度> s 时,Oracle就会舍入。
 
当s(scale)为负数时,Oracle就对小数点左边的s个数字进行舍入。
 
当s > p时, p表示小数点后第s位向左最多可以有多少位数字,如果大于p则Oracle报错,小数点后s位向右的数字被舍入.
 
NUMBER类型细讲
 
Oracle number datatype 语法:NUMBER[(precision [, scale])]
 简称:precision --> p
      scale    --> s
 
NUMBER(p, s)
 范围:1  保存数据范围:-1.0e-130  保存在机器内部的范围:1 ~ 22 bytes
 
有效位:从左边第一个不为0的数算起的位数。
 s的情况:
 s > 0
    精确到小数点右边s位,并四舍五入。然后检验有效位是否 s     精确到小数点左边s位,并四舍五入。然后检验有效位是否 s = 0
    此时NUMBER表示整数。

eg:
 Actual Data  Specified As  Stored As
 ----------------------------------------
 123.89          NUMBER        123.89
 123.89          NUMBER(3)    124
 123.89          NUMBER(6,2)  123.89
 123.89          NUMBER(6,1)  123.9
 123.89          NUMBER(4,2)  exceeds precision (有效位为5, 5 > 4)
 123.89          NUMBER(6,-2)  100
 .01234          NUMBER(4,5)  .01234 (有效位为4)
 .00012          NUMBER(4,5)  .00012
 .000127      NUMBER(4,5)  .00013
 .0000012      NUMBER(2,7)  .0000012
 .00000123    NUMBER(2,7)  .0000012
 1.2e-4          NUMBER(2,5)  0.00012
 1.2e-5          NUMBER(2,5)  0.00001
 123.2564      NUMBER        123.2564
 1234.9876    NUMBER(6,2)  1234.99
 12345.12345  NUMBER(6,2)  Error (有效位为5+2 > 6)
 1234.9876    NUMBER(6)    1235 (s没有表示s=0)
 12345.345    NUMBER(5,-2)  12300
 1234567      NUMBER(5,-2)  1234600
 12345678      NUMBER(5,-2)  Error (有效位为8 > 7)
 123456789    NUMBER(5,-4)  123460000
 1234567890    NUMBER(5,-4)  Error (有效位为10 > 9)
 12345.58      NUMBER(*, 1)  12345.6
 0.1          NUMBER(4,5)  Error (0.10000, 有效位为5 > 4)
 0.01234567    NUMBER(4,5)  0.01235
 
0.09999      NUMBER(4,5)  0.09999

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1236
24
Digital audio output interface on the motherboard-SPDIF OUT Digital audio output interface on the motherboard-SPDIF OUT Jan 14, 2024 pm 04:42 PM

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Mar 12, 2025 pm 05:48 PM

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

Which are the three leading virtual currency apps? Which are the three leading virtual currency apps? Mar 04, 2025 pm 08:51 PM

The virtual currency market is booming, and many trading platforms are born. This article will introduce the three leading applications in the virtual currency field, known for their excellent user experience, powerful security and rich features. These applications include Binance, gate.io and Ouyi, which provide investors with convenient and secure ways to buy, sell, trade and track virtual currencies.

Which digital currency app trading software is the best? Digital currency trading software big spot Which digital currency app trading software is the best? Digital currency trading software big spot Mar 07, 2025 pm 06:45 PM

There is no single "best" digital currency trading app, and the choice depends on personal needs. 1. OKX has powerful functions and rich currency types; 2. Binance has high liquidity and diverse transaction types; 3. Gate.io provides unique functions such as staking mining; 4. Huobi Global has a friendly interface and multi-language support; 5. Kraken focuses on security; 6. Coinbase is suitable for beginners and focuses on user education. When choosing, you need to consider security, liquidity, handling fees, functions, user experience and other factors.

Top 10 cryptocurrency exchange platforms in 2025 (Latest list) Top 10 cryptocurrency exchange platforms in 2025 (Latest list) Feb 14, 2025 pm 05:12 PM

Here are common sayings about the Top 10 cryptocurrency exchange platforms in 2025: Binance is a leading global leader, offering a wide range of currencies and trading pairs, but faces regulatory issues in some regions. Huobi has solid security measures and diversified token selection, which stands out in the global market. Coinbase is known for its compliance and ease of use, and is suitable for beginners. FTX focuses on cryptocurrency derivatives trading, with an advanced platform and low handling fees. OKX is popular in the Asian market, providing diversified services and low transaction fees.

Which currency trading software is better? Recommended platforms for the latest top ten virtual currency transactions in 2025 Which currency trading software is better? Recommended platforms for the latest top ten virtual currency transactions in 2025 Jan 16, 2025 am 11:11 AM

The choice of a virtual currency trading platform is crucial, and this article will recommend the ten best trading platforms in 2025. These platforms excel in areas such as security, user-friendliness, trading tools, and customer support. The following content will provide an in-depth analysis of the advantages of each platform to help investors find the trading platform that best suits their needs.

See all articles