Oracle's lack of a Bit datatype for table columns

后端 未结 9 987
醉酒成梦
醉酒成梦 2021-02-05 03:13

Oracle does not support a bit datatype or any other type for true/false scenarios. Does one use the char(1) field instead by using a specific letter to

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 04:02

    Oracle internally uses "bits" (not a datatype per se) in different Data Dictionary views.

    For example, dba_users view has :

    ..
            , DECODE (BITAND (u.spare1, 128), 128, 'YES', 'NO')
    ..
            , DECODE (BITAND (u.spare1, 256), 256, 'Y', 'N')
    ..
    

    which shows a way to workaround this in a way. If you don't have to modify "boolean" bits often, you could employ the same approach that Oracle had since Oracle 6 (at least). Create a table with a NUMBER column, and a VIEW on top of that that hides complexity of BITAND operations.

    ps. On a side note, Oracle JDBC has a "Bit" datatype https://docs.oracle.com/cd/E16338_01/appdev.112/e13995/oracle/jdbc/OracleTypes.html#BIT as well as you already know PL/SQL has Boolean. Although it probably doesn't help you much. See BITAND approach above if it suites your case.

提交回复
热议问题