(interbase之七) 使用域扩展interbase的数据类型

类别:数据库 点击:0 评论:0 推荐:

(interbase之七) 使用域扩展interbase的数据类型

原创kylixyqh
---------------------------------------------------------
一些人使用过一段时间的interbase后,抱怨说interbase提供的数据类型太少了。的确,与其他关系数据库相比,interbase确实提供了为数不多的数据类型,但是,实际上只要用心思考一下,就会发现interbase的域对象可以帮助我们在基本数据类型的基础上扩展很多有用的数据类型。事实上,经过这种扩展后,你会发现interbase的数据类型基本上和sybase11.9、Ms SqL server2000提供的数据类型相当。
1、逻辑数据类型boolean(取值范围0或1)
有两种方法实现布尔逻辑类型。
方法之一:使用整数0和1代表逻辑真和假。
create domain boolean as smallint default 0 check(value in (0,1));
方法之二:使用字符'0'和'1'代表逻辑真和假。
create domain boolean as char default '0' check (value in ('0','1'));
2、货币数据类型money、smallmoney
由于interbase6。0的dialect 3已经实现了大型精确数据,完全可以使用numeric类型构造出货币类型。
money类型:
create domain money as numeric(18,4);
smallmoney类型:
create domain smallmoney as numeric(9,4);
你可以根据实际情况改变长度和小数点位数使之符合你的要求。
3、其他整数类型tinyint、bigint
tinyint类型(0~255):
create domain tinyint as integer check(value between 0 and 255);
bigint类型(-2的63次方~2的63次方-1):
create domain bigint as numeric(18,0);
4、图像类型image
通过BLOB类型的子类型构造。
create domain image as blob sub_type 0
5、文本类型text
通过BLOB类型的子类型构造。
create domain text as blob sub_type 1
6、用户自定义数据类型
使用域,你可以象其他关系数据库一样创建丰富多彩的功能各异的自定义数据类型。

注:关于interbase6的基本数据类型,请参考有关资料。

本文地址:http://com.8s8s.com/it/it21327.htm