一般Oracle结果表 [英] General Oracle Results Table

查看:148
本文介绍了一般Oracle结果表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个新的实验室数据库。我想在一个表( RESULTS )中的所有原始结果(所有测试)。然而,数值在数量和精度上变化很大。例如,一些结果只是一个整数,而其他结果来自高度敏感的设备。



下面哪种情况是理想的(以及为什么)?



选项1:将每个结果存储在 raw_result 列中作为允许最高精度的NUMBER。





选项2:创建 RESULTS 表和多个子表,类似数据类型的结果和 raw_result 列作为具有该类型的特定精度的NUMBER。 (即:从1到1000的整数,十进制数到6个小数位等)



此外,在相关的帖子一般Oracle数据收集存储,我问过在这个数据库中存储原始信号的理想方式。

解决方案

使用选项1.无论精度和规模如何,NUMBER都是Oracle内部的NUMBER。
$ b

选项2似乎是一个可怕的维护噩梦从开始,如果你决定改变你的值的精度,你会做什么?



编辑:为了说明,请考虑:

  SQL> CREATE TABLE测试(n1 NUMBER(38,12),n2 NUMBER(5)); 

创建的表
SQL> INSERT INTO testing VALUES(1,1);

插入1行
SQL> INSERT INTO testing VALUES(990,9900);

插入1行
SQL> INSERT INTO testing VALUES(1999999.999999,1);

插入1行
SQL> SELECT n1,DUMP(n1)n1d,n2,DUMP(n2)n2d FROM test;

N1 N1D N2 N2D
--------------------- ------------- ----------------- ------ --------------------
1.000000000000 Typ = 2 Len = 2:193,2 1 Typ = 2 Len = 2:193,2
990.000000000000 Typ = 2 Len = 3:194,10,91 9900 Typ = 2 Len = 2:194,100
1999999.999999000000 Typ = 2 Len = 8:196,2,100,100,100 1 Typ = 2 Len = 2:193,2
,100,100,100
SQL>

存储空间没有区别。存储的长度是数据相关的,而不是列定义的精度/范围。



这个链接给出了如何存储NUMBER类型的很好的解释。它不是简单的比较的值,以了解一个给定的数字将需要多少存储空间。例如,它需要3个字节存储数字990,但只有2个字节存储9900.


I am designing a new laboratory database. I want all the raw results (for all tests) in one table (RESULTS). However, the numerical values vary greatly in quantity and precision. For example, some results are simply a whole number count, while other results come from highly sensitive equipment.

Which case below is ideal (and why)?

Option 1: Store each result in a raw_result column as a NUMBER with the highest precision allowed.

OR

Option 2: Create the RESULTS table and several child tables each representing results of a similar data type and a raw_result column as a NUMBER with a specific precision for that type. (ie: integer from 1 to 1000, decimal number to 6 decimal places, etc)

Also, in a related post General Oracle Data Collection Storage, I asked about the ideal way to store raw signals in this database.

解决方案

Use option 1. A NUMBER is a NUMBER internally to Oracle, regardless of precision and scale.

Option 2 appears to be a horrible maintenance nightmare from the get-go, and what do you do if you decide to change the precision of one of your values?

EDIT: to illustrate, consider:

    SQL> CREATE TABLE testing (n1 NUMBER(38,12), n2 NUMBER(5));

    Table created
    SQL> INSERT INTO testing VALUES (1, 1);

    1 row inserted
    SQL> INSERT INTO testing VALUES (990, 9900);

    1 row inserted
    SQL> INSERT INTO testing VALUES (1999999.999999, 1);

    1 row inserted
    SQL> SELECT n1, DUMP(n1) n1d, n2, DUMP(n2) n2d FROM testing;

                   N1 N1D                                N2 N2D
--------------------- ------------------------------ ------ --------------------
       1.000000000000 Typ=2 Len=2: 193,2                  1 Typ=2 Len=2: 193,2
     990.000000000000 Typ=2 Len=3: 194,10,91           9900 Typ=2 Len=2: 194,100
 1999999.999999000000 Typ=2 Len=8: 196,2,100,100,100      1 Typ=2 Len=2: 193,2
                      ,100,100,100                          
    SQL> 

No difference in storage. The length stored is data dependent, not the precision/scale of the column definition.

This link gives a pretty good explanation of how the NUMBER type is stored. It's not as simple as comparing the values to get an idea of how much storage it will take for a given number. For example, it takes 3 bytes to store the number 990, but only 2 bytes to store 9900.

这篇关于一般Oracle结果表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆