SQL Server和Oracle中外理bool类型的方式

来源:互联网 发布:淘宝ps教程自学视频 编辑:程序博客网 时间:2024/05/18 00:46

SQL Server一般用bit类型即可,数据库中存储的是0(false)或1(true)。

Oralce没有表示是否的类型,但可用数字型number(1)或字符型代替char(1)。

 

 /// <summary>
  /// Converter to use boolean data type with Oracle
  /// </summary>
  /// <param name="value">Value to convert</param>
  /// <returns></returns>
  public static string OraBit(bool value) {
   if(value)
    return "Y";
   else
    return "N";
  }

 

  /// <summary>
  /// Converter to use boolean data type with Oracle
  /// </summary>
  /// <param name="value">Value to convert</param>
  /// <returns></returns>
  public static bool OraBool(string value) {
   if(value.Equals("Y"))
    return true;
   else
    return false;
  }

原创粉丝点击