oracle 常用数据类型

1. String Type:
CHAR( <SIZE> <BYTE|CHAR> ): 定长; 字符编码使用default NLS setting; 最多2000bytes
NCHAR( <SIZE> ):定长;  字符编码使用database's national character set;最多2000bytes

VARCHAR2( <SIZE> <BYTE|CHAR> ):变长;字符编码使用default NLS setting;最多4000bytes
NVARCHAR2( <SIZE> ):变长;字符编码使用database's national character set;最多4000bytes

长度:
定长:如果字符没有达到指定的长度,则在后面添加space填满。这会导致很多麻烦,比如判断两个字符串是否相等;而且也可能浪费空间。因此: 不要使用定长的!

CHAR和VARCHAR2中:BYTE和CHAR的区别
BYTE指定空间的字节数,CHAR指明字符个数 (注意如在UTF-8zhong,有些字符可以占多个字节)。一般要使用CHAR而不是BYTE。
one very common issue people encounter  when using multibyte character sets, namely that a VARCHAR2(N) doesn’t necessarily hold N characters but rather N bytes. 

NCHAR和NVARCHAR2:
长度只使用字符个数。


字符编码:
NLS(National Language Support): 
在oracle中可以设置。

database's national character set:(Unicode
In Oracle9i and above, the database’s national character set may take one of two values: UTF8 or 
AL16UTF16 (UTF-16 in 9i; AL16UTF16 in 10g). This makes the NCHAR and NVARCHAR types suitable for storing
only multibyte data, which

小心字符编码间的转换!有可能会丢失信息。

2. Binary Data:
RAW( <size> ):变长。长度单位是byte。最大为2000bytes。

字符和Raw间的转换函数:
• HEXTORAW: To convert strings of hexadecimal characters to the RAW type
 RAWTOHEX: To convert RAW strings to hexadecimal strings

3. Number:
NUMBER( p, s ):
p: Precision, or the total number of digits  
s: Scale, or the number of digits to the right of the decimal point
范围:   1   <=   p   <=38,   -84   <=   s   <=   127
保存数据范围:-1.0e-130   <=   number   value   <   1.0e+126        
保存在机器内部的范围:   1   ~   22   bytes

s >0时:精确到小数点后面s位。然后检查:小数点前面的有效位(从左边非0位开始数)+ s  <= p
s == 0  时:表示整数。检查有效位 <= p     
s < 0时:精确到小数点前面s位。检查:有效位 + s <= p (即左边因为s产生的0不算在p之类)

BINARY_FLOAT:  空间占32bit       6-7位有效数字         -3.4E-38     到     3.4E38  
BINARY_DOUBLE: 空间占64bit     15~16位有效数字     -1.7E-308   到     1.7E308
对应IEEE中单精度和双精度浮点数。Oracle10g才加入。

对比:
精度:Number比这float和double的精度都高多了,Number是38位。在对精度要求很高的应用中(如financial application),千万不用使用这两个,而是使用Number类型。
数的表示范围:Number比float大,比double小。
速度:Float和Double有硬件直接支持,而Number需要用软件实现,因此Number速度慢很多。(可以用Number来存储数据,然后运算时先用CAST函数转换成float或double)

4. 日期:
DATE: 
The DATE type is a fixed-width 7-byte date/time datatype. It will always contain the seven attributes of
the century, the year within the century, the month, the day of the month, the hour, the minute, and the
second.

TIMESTAMP(n):支持fractional second
fixed-width 7- or 11-byte date/time datatype
n可选,n可取0~9,表示秒后面的小数点位数



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值