Oracle number类型的语法和用法
Oracle NUMBER类型对大多数应用来讲都是最佳的选择。不过,这个类型会带来一些性能影响。Oracle NUMBER类型是一种软件数据类型,
Oracle number类型的语法很简单,就是:
number(p,s)
p,s都是可选的,假如都不填,p默认为38,s默认为-48~127。
1. 精度(precision),或总位数。默认情况下,精度为38位,取值范围是1~38之间。也可以用字符*表示38。
2. 小数位置(scale),或小数点右边的位数。小数位数的合法值为-48~127,其默认值取决于是否指定了精度。如果没有知道精度,小数位数则默认有最大的取值区间。如果指定了精度,小数位数默认为0(小数点右边一位都没有)。例如,定义为NUMBER的列会存储浮点数(有小数),而NUMBER(38)只存储整数数据(没有小数),因为在第二种情况下小数位数默认为0.
如下SQL语句:
create table t ( msg varchar2(12.), num_col number(5,2) );
insert into t (msg,num_col) values ( '123.456', 123.456 );//执行成功,保存的是123.46
insert into t (msg,num_col) values ( '1234', 1234 );//执行失败,要保留2位小数,,那么整数位最多3位,现在是4位。
如果scale是负数怎么样,表示左边整数位舍入几位:
create table t ( msg varchar2(12.), num_col number(5,-2) );
insert into t (msg,num_col) values ( '123.45', 123.45 );//执行成功,保存的是100
insert into t (msg,num_col) values ( '123.456', 123.456 );//执行成功,保存的是100
其他数据类型:
1. NUMERIC(p,s):完全映射至NUMBER(p,s)。如果p未指定,则默认为38.
2. DECIMAL(p,s)或DEC(p,s):完全映射至NUMBER(p,s)。如果p为指定,则默认为38.
3. INTEGER或INT:完全映射至NUMBER(38)类型。
4. SMALLINT:完全映射至NUMBER(38)类型。
5. FLOAT(b):映射至NUMBER类型。
6. DOUBLE PRECISION:映射至NUMBER类型。
7. REAL:映射至NUMBER类型。
性能考虑:
一般而言,Oracle NUMBER类型对大多数应用来讲都是最佳的选择。不过,这个类型会带来一些性能影响。Oracle NUMBER类型是一种软件数据类型,在Oracle软件本身中实现。我们不能使用固有硬件操作将两个NUMBER类型相加,这要在软件中模拟。不过,浮点数没有这种实现。将两个浮点数相加时,Oracle会使用硬件来执行运算。
换而言之,将一些列的number列相加,没有将一系列float列相加来得快。因为float列的精度低很多,一般是6~12位。
比如:select sum(ln(cast( num_type as binary_double ) )) from t
比:select sum(ln(cast( num_type) )) from t 要快很多。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.
