在Oracle中的布尔场 [英] Boolean Field in Oracle

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

问题描述

昨天,我想一个布尔字段添加到Oracle表。然而,实际上不是Oracle中的布尔数据类型。有谁知道这里来模拟一个布尔值的最佳方式?谷歌搜索的主题发现的几个方法


  1. 使用整数,只是不打扰它分配比0或1的任何其他。


  2. 使用一个char字段Y或N作为唯一的两个值。


  3. 使用与CHECK约束的枚举。


请有经验的Oracle开发人员知道哪种方法preferred /规范?


解决方案

我发现<一个href=\"http://www.techrepublic.com/article/oracle-tip-choosing-an-efficient-design-for-boolean-column-values/\">this链接有用的。

下面是一段突出一些/缺点每种方法的优点的。


  

最常见的设计是模仿许多布尔样
  标志Oracle的数据字典视图使用,选择'Y'真正的
  和'N'假。然而,与主机的正确交互
  的环境中,如JDBC,OCCI和其他编程环境中,
  这是更好地为真正的选择0为假,1所以它可以工作
  正确地与getBoolean和setBoolean功能。


基本上他们主张方法号2,求效益的缘故,使用


  • 的0/1(因为互操作性的JDBC的 getBoolean()等)检查约束

  • 一个的键入的CHAR的(因为它采用了比数小的空间)。

他们的例子:


 创建表tbool(布尔焦检查(在布尔(0,1));
插入tbool值(0);
插入tbool值(1);`


Yesterday I wanted to add a boolean field to an Oracle table. However, there isn't actually a boolean data type in Oracle. Does anyone here know the best way to simulate a boolean? Googling the subject discovered several approaches

  1. Use an integer and just don't bother assigning anything other than 0 or 1 to it.

  2. Use a char field with 'Y' or 'N' as the only two values.

  3. Use an enum with the CHECK constraint.

Do experienced Oracle developers know which approach is preferred/canonical?

解决方案

I found this link useful.

Here is the paragraph highlighting some of the pros/cons of each approach.

The most commonly seen design is to imitate the many Boolean-like flags that Oracle's data dictionary views use, selecting 'Y' for true and 'N' for false. However, to interact correctly with host environments, such as JDBC, OCCI, and other programming environments, it's better to select 0 for false and 1 for true so it can work correctly with the getBoolean and setBoolean functions.

Basically they advocate method number 2, for efficiency's sake, using

  • values of 0/1 (because of interoperability with JDBC's getBoolean() etc.) with a check constraint
  • a type of CHAR (because it uses less space than NUMBER).

Their example:

create table tbool (bool char check (bool in (0,1));
insert into tbool values(0);
insert into tbool values(1);`

这篇关于在Oracle中的布尔场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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