在oracle数据库中是否存在布尔类型?

时间:2021-12-04 07:43:14

Is there a boolean type in oracle databases, similar to the BIT datatype in MS SQL?

在oracle数据库中是否存在类似于MS SQL中的BIT数据类型的布尔类型?

10 个解决方案

#1


173  

Not only is the boolean datatype missing in Oracle's SQL (not PL/SQL), but they also have no clear recommendation about what to use instead. See this thread on asktom. From recommending CHAR(1) 'Y'/'N' they switch to NUMBER(1) 0/1 when someone points out that 'Y'/'N' depends on the English language, while e.g. German programmers might use 'J'/'N' instead.

不仅在Oracle的SQL(不是PL/SQL)中丢失了布尔数据类型,而且他们也没有明确的推荐使用什么。请在asktom上看到这条线。从推荐CHAR(1)当有人指出“Y”/“N”依赖于英语时,他们会转而使用NUMBER(1) 0/1,而德国程序员则可能用“J”/“N”来代替。

The worst thing is that they defend this stupid decision just like they defend the ''=NULL stupidity.

最糟糕的是,他们为这个愚蠢的决定辩护,就像他们为“愚蠢的愚蠢”辩护一样。

#2


30  

Nope.

不。

Can use:

可以使用:

IS_COOL NUMBER(1,0)

1 - true
0 - false

--- enjoy Oracle

推荐- - - - - -享受甲骨文

Or use char Y/N as described here

或者用这里描述的char /N。

#3


24  

As per Ammoq and kupa's answers, We use number(1) with default of 0 and don't allow nulls.

根据Ammoq和kupa的答案,我们使用默认为0的数字(1),不允许null。

here's an add column to demonstrate:

这里有一个添加栏来演示:

ALTER TABLE YourSchema.YourTable ADD (ColumnName NUMBER(1) DEFAULT 0 NOT NULL);

Hope this helps someone.

希望这可以帮助别人。

#4


14  

Not at the SQL level and that's a pity There is one in PLSQL though

不是SQL级别的,遗憾的是PLSQL中有一个。

#5


8  

No there doesn't exist type boolean,but instead of this you can you 1/0(type number),or 'Y'/'N'(type char),or 'true'/'false' (type varchar2).

不存在类型布尔型,但你可以用1/0(类型号),或“Y”/“N”(类型char),或“true”/“false”(类型varchar2)。

#6


5  

There is a boolean type for use in pl/sql, but none that can be used as the data type of a column.

在pl/sql中有一个boolean类型,但是没有一个可以用作列的数据类型。

#7


4  

A common space-saving trick is storing boolean values as an Oracle CHAR, rather than NUMBER:

一个常用的节省空间的技巧是将布尔值存储为一个Oracle CHAR,而不是数字:

#8


3  

Just because nobody mentioned it yet: using RAW(1) also seems common practice.

只是因为没有人提到它:使用RAW(1)似乎也是常见的做法。

#9


2  

No, there isn't a boolean type in Oracle Database, but you can do this way:

不,Oracle数据库中没有布尔类型,但是您可以这样做:

You can put a check constraint on a column.

您可以在列上设置检查约束。

If your table hasn't a check column, you can add it:

如果您的表没有检查列,您可以添加:

ALTER TABLE table_name
ADD column_name_check char(1) DEFAULT '1';

When you add a register, by default this column get 1.

当你添加一个寄存器时,默认情况下,这个列是1。

Here you put a check that limit the column value, just only put 1 or 0

在这里,你要做一个限制列值的检查,只需要输入1或0。

ALTER TABLE table_name ADD
CONSTRAINT name_constraint 
column_name_check (ONOFF in ( '1', '0' ));

#10


-1  

DECLARE
error_flag  BOOLEAN := false;
BEGIN

error_flag := true;
--error_flag := 13;--expression is of wrong type

  IF error_flag THEN 

UPDATE table_a SET id= 8 WHERE id = 1;

END IF;
END;

#1


173  

Not only is the boolean datatype missing in Oracle's SQL (not PL/SQL), but they also have no clear recommendation about what to use instead. See this thread on asktom. From recommending CHAR(1) 'Y'/'N' they switch to NUMBER(1) 0/1 when someone points out that 'Y'/'N' depends on the English language, while e.g. German programmers might use 'J'/'N' instead.

不仅在Oracle的SQL(不是PL/SQL)中丢失了布尔数据类型,而且他们也没有明确的推荐使用什么。请在asktom上看到这条线。从推荐CHAR(1)当有人指出“Y”/“N”依赖于英语时,他们会转而使用NUMBER(1) 0/1,而德国程序员则可能用“J”/“N”来代替。

The worst thing is that they defend this stupid decision just like they defend the ''=NULL stupidity.

最糟糕的是,他们为这个愚蠢的决定辩护,就像他们为“愚蠢的愚蠢”辩护一样。

#2


30  

Nope.

不。

Can use:

可以使用:

IS_COOL NUMBER(1,0)

1 - true
0 - false

--- enjoy Oracle

推荐- - - - - -享受甲骨文

Or use char Y/N as described here

或者用这里描述的char /N。

#3


24  

As per Ammoq and kupa's answers, We use number(1) with default of 0 and don't allow nulls.

根据Ammoq和kupa的答案,我们使用默认为0的数字(1),不允许null。

here's an add column to demonstrate:

这里有一个添加栏来演示:

ALTER TABLE YourSchema.YourTable ADD (ColumnName NUMBER(1) DEFAULT 0 NOT NULL);

Hope this helps someone.

希望这可以帮助别人。

#4


14  

Not at the SQL level and that's a pity There is one in PLSQL though

不是SQL级别的,遗憾的是PLSQL中有一个。

#5


8  

No there doesn't exist type boolean,but instead of this you can you 1/0(type number),or 'Y'/'N'(type char),or 'true'/'false' (type varchar2).

不存在类型布尔型,但你可以用1/0(类型号),或“Y”/“N”(类型char),或“true”/“false”(类型varchar2)。

#6


5  

There is a boolean type for use in pl/sql, but none that can be used as the data type of a column.

在pl/sql中有一个boolean类型,但是没有一个可以用作列的数据类型。

#7


4  

A common space-saving trick is storing boolean values as an Oracle CHAR, rather than NUMBER:

一个常用的节省空间的技巧是将布尔值存储为一个Oracle CHAR,而不是数字:

#8


3  

Just because nobody mentioned it yet: using RAW(1) also seems common practice.

只是因为没有人提到它:使用RAW(1)似乎也是常见的做法。

#9


2  

No, there isn't a boolean type in Oracle Database, but you can do this way:

不,Oracle数据库中没有布尔类型,但是您可以这样做:

You can put a check constraint on a column.

您可以在列上设置检查约束。

If your table hasn't a check column, you can add it:

如果您的表没有检查列,您可以添加:

ALTER TABLE table_name
ADD column_name_check char(1) DEFAULT '1';

When you add a register, by default this column get 1.

当你添加一个寄存器时,默认情况下,这个列是1。

Here you put a check that limit the column value, just only put 1 or 0

在这里,你要做一个限制列值的检查,只需要输入1或0。

ALTER TABLE table_name ADD
CONSTRAINT name_constraint 
column_name_check (ONOFF in ( '1', '0' ));

#10


-1  

DECLARE
error_flag  BOOLEAN := false;
BEGIN

error_flag := true;
--error_flag := 13;--expression is of wrong type

  IF error_flag THEN 

UPDATE table_a SET id= 8 WHERE id = 1;

END IF;
END;