首页 > 数据库 >[转帖]Oracle NUMBER Data Type

[转帖]Oracle NUMBER Data Type

时间:2024-02-18 09:01:06浏览次数:24  
标签:data number NUMBER 转帖 following precision Oracle Type

https://www.oracletutorial.com/oracle-basics/oracle-number-data-type/

 

Summary: in this tutorial, you will learn about the Oracle NUMBER data type and how to use it to define numeric columns for a table.

Introduction to Oracle NUMBER data type

The Oracle NUMBER data type is used to store numeric values that can be negative or positive. The following illustrates the syntax of the NUMBER data type:

NUMBER[(precision [, scale])]
Code language: SQL (Structured Query Language) (sql)

The Oracle NUMBER data type has precision and scale.

  • The precision is the number of digits in a number. It ranges from 1 to 38.
  • The scale is the number of digits to the right of the decimal point in a number. It ranges from -84 to 127.

For example, the number 1234.56 has a precision of 6 and a scale of 2. So to store this number, you need NUMBER(6,2).

Both precision and scale are in decimal digits and optional. If you skip the precision and scale, Oracle uses the maximum range and precision for the number.

For example, the following form defines a number that can store numeric values with the maximum range and precision:

NUMBER
Code language: SQL (Structured Query Language) (sql)

The following syntax defines a fixed-point number:

NUMBER(p,s)
Code language: SQL (Structured Query Language) (sql)

To define an integer, you use the following form:

NUMBER(p)
Code language: SQL (Structured Query Language) (sql)

The above form represents a fixed-point number with precision p and a scale of zero, which is equivalent to the following:

NUMBER(p,0)
Code language: SQL (Structured Query Language) (sql)

Oracle allows the scale to be negative, for example, the following number will round the numeric value to hundreds.

NUMBER(5,-2)
Code language: SQL (Structured Query Language) (sql)

Note that if you insert a number into a NUMBER(p,s) column and the number exceeds precision p, Oracle will issue an error. However, if the number exceeds the scale, Oracle will round the value.

Oracle NUMBER data type examples

The following statement creates a table named number_demo that consists of a numeric column:

CREATE TABLE number_demo ( 
    number_value NUMERIC(6, 2) 
);
Code language: SQL (Structured Query Language) (sql)

The following INSERT statements insert three numbers into the number_demo table:

INSERT INTO number_demo
VALUES(100.99);

INSERT INTO number_demo
VALUES(90.551);

INSERT INTO number_demo
VALUES(87.556);
Code language: SQL (Structured Query Language) (sql)

In this example:

  • The first value was inserted successfully because the number was in the range defined for the column.
  • The second value was rounded down and the third value was rounded up because the column accepted only numbers with two decimal point places.

The following example inserts the maximum and minimum values that the number_value can accept:

INSERT INTO number_demo
VALUES(9999.99);

INSERT INTO number_demo
VALUES(-9999.99);
Code language: SQL (Structured Query Language) (sql)

The following example causes an error because the inserted value exceeds the precision defined for the column.

INSERT INTO number_demo
VALUES(-10000);
Code language: SQL (Structured Query Language) (sql)

Consider the following example:

INSERT INTO number_demo
VALUES(9999.999);
Code language: SQL (Structured Query Language) (sql)

In this example, the value was rounded up which resulted in a number that exceeded the precision defined for the column.

Oracle NUMBER data type aliases

Oracle contains a number of aliases that you can use to define numeric columns as shown in the following table:

ANSI data typeOracle NUMBER data type
INT NUMBER(38)
SMALLINT NUMBER(38)
NUMBER(p,s) NUMBER(p,s)
DECIMAL(p,s) NUMBER(p,s)

Note that INTSMALLINTNUMERIC, and DECIMAL are just aliases. They are not the real data types. Internally, Oracle maps these aliases to the corresponding NUMBER data type.

In this tutorial, you have learned the Oracle NUMBER data type and how to use it to define numeric columns for a table.

标签:data,number,NUMBER,转帖,following,precision,Oracle,Type
From: https://www.cnblogs.com/jinanxiaolaohu/p/17984213

相关文章

  • VSCOde+Nodejs+Typescript前端开发环境
    1.安装Node.js下载地址:https://nodejs.org/enlts版本:长久稳定版本安装:默认安装就可以了验证:node2.VSCode下载地址:https://code.visualstudio.com/Download安装:默认安装语言切换:安装中文插件,重启 2.1修改终端cmd模式:1.点击设置图标,选择CommandPalette 2.输入:Ter......
  • 【常见问题】Java 8 date time type `java.time.LocalDateTime` not supported by def
    问题描述将一个包含LocalDateTime对象的集合进行序列化和反序列化时,可能会遇到以下异常:Causedby:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:Java8date/timetype`java.time.LocalDate`notsupportedbydefault:addModule"com.fasterxml.jack......
  • IfcBeamTypeEnum
    IfcBeamTypeEnum类型定义此枚举定义不同预定义类型的梁,这些梁可以进一步指定IfcBeam或IfcBeamType。  IFC2x2中的新枚举类型。IFC4添加了枚举器HOLLOWCORE和SPANDREL。  EnumerationdefinitionConstantDescriptionBEAMAstandardbeamusuallyusedhorizontal......
  • IfcBuildingSystemTypeEnum
    IfcBuildingSystemTypeEnum 类型定义此枚举标识不同类型的建筑系统。 IFC4中的新枚举。 EnumerationdefinitionConstantDescriptionFENESTRATIONSystemofdoors,windows,andotherfillingsinopeninginabuildingenvelopthataredesignedtopermitth......
  • [转帖]NUMBER长度的误解
    https://cloud.tencent.com/developer/article/1615838 我们看下官方文档对NUMBER类型的介绍,TheNUMBERdatatypestoreszeroaswellaspositiveandnegativefixednumberswithabsolutevaluesfrom1.0x10-130tobutnotincluding1.0x10126.Ifyouspecif......
  • Go 100 mistakes - #10: Not being aware of the possible problems with type embedd
     Becausethemutexisembedded,wecandirectlyaccesstheLockandUnlockmethods fromtheireceiver.Wementionedthatsuchanexampleisawrongusageoftypeembedding.What’s thereasonforthis?Sincesync.Mutexisanembeddedtype,theLockand......
  • IfcColumnTypeEnum
    IfcColumnTypeEnum类型定义此枚举定义不同的预定义列类型,这些列可以进一步指定IfcColumn或IfcColumnType。 IFC2x2中的新枚举。 EnumerationdefinitionConstantDescriptionCOLUMNAstandardmemberusuallyverticalandrequiringresistancetoverticalforces......
  • Oracle Java SE Product Releases
    1.gotothemainpage[https://www.oracle.com/]2.thenclick'Products'tochoosetheJavaicon3.clickthe'OracleJavaSEPlatform'icon[https://www.oracle.com/java/]4.repeattheactionasbelow[https://www.oracle.com/java/t......
  • SharePoint Online "Content Type Gallery" 简介
    前言在使用SharePointOnline的时候,我们经常会使用内容类型,用来确保数据格式在多个列表中保持一致,然而,跨站点的时候,还是依旧容易出现问题,这里我们就需要用到内容类型集了。正文1.既然是可以跨网站使用的内容类型,那么就需要来到管理中心来创建了,首先来到Microsoft3......
  • 解决Oracle11g区分大小写问题
    连接到:OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-ProductionWiththePartitioning,OLAP,DataMiningandRealApplicationTestingoptionsSQL>showparametersec_case_sensitive_logonNAMETYPEVALU......