NUMBER Data Type

本文详细解释了Oracle NUMBER 数据类型的特性,包括它如何存储从1.0x10^-130到但不包括1.0x10^126的正数和负数固定数值,以及如何使用其形式和参数(精度和刻度)来定义和操作这些数值。

The<wbr><code style="font-family:monospace; font-size:12px">NUMBER</code><wbr>data type stores zero as well as<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:19px"><strong>positive(肯定的,确定的,正数)</strong></span>and negative(负数,负的) fixed numbers with<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:19px"><strong>absolute values(绝对值)</strong></span><wbr>from 1.0 x 10<sup>-130</sup><wbr>to but not including 1.0 x 10<sup>126</sup>. If you specify an<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:19px"><strong>arithmetic(算术)</strong></span><wbr><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:19px"><strong>expression_r(表达,表达式)</strong></span>whose value has an absolute value greater(大于) than or equal to 1.0 x 10<sup>126</sup>, then Oracle returns an error. Each<wbr><code style="font-family:monospace; font-size:12px">NUMBER</code><wbr>value<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:19px"><strong>requires(需要)</strong></span>from 1 to 22 bytes.</wbr></wbr></wbr></wbr></wbr></wbr></wbr>

Specify a fixed-point number using thefollowing form(以下形式):

NUMBER(p,s)

where(其中):

  • p<wbr>is the<wbr><span style="word-wrap:normal; word-break:normal; line-height:21px; font-weight:bold"><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">precision(精度)</span></span>, or the maximum number of<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>significant(重大的,有效的)</strong></span><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">decimal digits(小数位数)</span></strong>, where the<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>most(大部分的)</strong></span>significant digit is the left-most<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">nonzero digit(非零的数字)</span></strong>, and the<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">least(最</span></strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>小的,最少的)</strong></span>significant digit is the right-most<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>known digit(已知位数)</strong></span>. Oracle<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>guarantees(保证)</strong></span>the<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">portability(轻便,可移植性的)</span></strong>of numbers with precision of up to 20 base-100 digits,<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">which(这是)</span></strong>is<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>equivalent to(相当于,等价于)</strong></span>39 or 40 decimal digits depending on the<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>position(位置)</strong></span>of the<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">decimal point(小数点)</span></strong>.</wbr></wbr>

  • s<wbr>is the<wbr><span style="word-wrap:normal; word-break:normal; line-height:21px; font-weight:bold"><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">scale(刻度,比例,规模)</span></span>, or the number of digits from the decimal point to the least significant digit. The scale can<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>range(范围,幅度)</strong></span>from -84 to 127.</wbr></wbr>

    • 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 theleft side(左侧)of the decimal point, because theactual data(实际数据)isrounded to(四舍五入到)the specified number of places to the left of the decimal point. For example, aspecification(规格,规范)of (10,-2) means toround(圆)to hundreds.

Scale can be(能够,可以)<wbr><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">greater(大于)</span></strong>than precision, most<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>commonly</strong></span><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">(最常用的)</span></strong>when<wbr><code style="font-family:monospace; font-size:12px">e</code><wbr><strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">notation(注释,标记)</span></strong>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<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>defined(定义)</strong></span>as<wbr><code style="font-family:monospace; font-size:12px">NUMBER(4,5)</code><wbr>requires a zero for the first digit after the decimal point and rounds all values<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">past(过去,往事)</span></strong>the fifth digit after the decimal point.</wbr></wbr></wbr></wbr></wbr>

It is good practice(好做法)<wbr>to specify the scale and precision of a fixed-point number column for<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">extra(额外)</span></strong>integrity<span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px"><strong>(完整)</strong></span><wbr>checking on<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">(检查,核实)</span></strong>input. Specifying scale and precision does not force all values to a fixed length. If a value<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">exceeds(超过)</span></strong>the precision, then Oracle returns an error. If a value exceeds the scale, then Oracle<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">rounds it(四舍五入)</span></strong>.</wbr></wbr>

Specify aninteger(整数)using the following form:

NUMBER(p)

Thisrepresents(代表)a fixed-point number with precision<wbr><code style="font-family:monospace; font-size:12px"><span style="word-wrap:normal; word-break:normal; line-height:18px; font-style:italic">p</span></code><wbr>and scale 0 and is<strong><span style="color:#ED1C24; word-wrap:normal; word-break:normal; line-height:21px">equivalent to(相当于)</span></strong><wbr><code style="font-family:monospace; font-size:12px">NUMBER(p,0)</code>.</wbr></wbr></wbr>

Specify afloating-point number(浮点数)using the following form:

NUMBER

The absence(没有) of precision and scale designators(指定这,标志符) specifies the maximum range and precision for an Oracle number.

See Also(另见):

"Floating-Point Numbers"

Table 3-2<wbr>show how Oracle stores data using different precisions and scales.</wbr>

Interface(接口)和 Data Type(数据类型)在编程领域存在多方面的区别。 ### 概念层面 - **Interface**:是一种抽象的类型,它定义了一组方法的签名,但不包含方法的实现。在 Go 语言中,interface 有 iface(非空接口,包含方法的接口)和 eface(空接口)两种底层实现,是数据类型转换成 interface 之后的实体的 struct 结构;在 TypeScript(TS)里,interface 用于定义对象的结构,规定对象应具备的属性和方法。如 TS 中定义 `interface News { code: number; msg: string; data?: { title: string; content: string } }`,明确了 `News` 对象需有 `code`、`msg` 等属性 [^2][^3][^4]。 - **Data Type**:是对数据的一种分类,规定了数据的存储方式、取值范围以及可进行的操作。像整数类型(int)、浮点数类型(float)、字符串类型(string)等,不同的数据类型在内存中占用的空间和能执行的操作都不同。 ### 用途层面 - **Interface**:主要用于实现多态,让不同的数据类型通过实现相同的接口,以统一的方式被使用。例如在 Go 语言中,多个不同的结构体只要实现了某个接口的所有方法,就可以将这些结构体的实例赋值给该接口类型的变量,从而实现代码的灵活性和可扩展性。 - **Data Type**:用于存储和表示数据,不同的数据类型适用于不同的数据存储需求。例如,用整数类型存储整数,用字符串类型存储文本信息。 ### 语法层面 - **Interface**:在不同语言中有不同的语法定义。在 Go 语言中,通过关键字 `interface` 定义接口,如 `type Reader interface { Read(p []byte) (n int, err error) }`;在 TS 中,使用 `interface` 关键字定义接口,并且可以通过 `extends` 关键字实现接口的继承,如 `interface Viewnews extends News { price: number; total: number }` [^4]。 - **Data Type**:在各种编程语言中,数据类型的定义通常是内置的或者通过特定的关键字定义。例如在 Python 中,有 `int`、`float`、`str` 等内置数据类型;在 Java 中,使用 `int`、`double`、`String` 等关键字定义数据类型。 ### 底层实现层面 - **Interface**:Go 语言中,interface 有 iface 和 eface 两种底层实现。eface 用于空接口,包含 `_type` 和 `data` 两个字段,`_type` 负责决定 `data` 应该如何解释和操作,`data` 指向具体的实例数据;iface 用于非空接口,包含 `tab` 和 `data` 两个字段,其中 `tab` 指向一个 `itab` 结构体,包含了接口和具体类型的信息 [^2]。 - **Data Type**:不同的数据类型在底层有不同的存储方式和操作方式。例如,整数类型通常以二进制补码的形式存储在内存中,而字符串类型可能以字符数组的形式存储。 ```typescript // TS 中 interface 示例 interface Animal { name: string; speak(): void; } class Dog implements Animal { name: string; constructor(name: string) { this.name = name; } speak() { console.log(`${this.name} says woof!`); } } // 数据类型示例 let num: number = 10; let str: string = "Hello"; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值