Is there any Boolean type in Oracle databases, similar to the BIT
datatype in Ms SQL Server?
Oracle数据库中是否有任何布尔类型,类似于Ms SQL Server中的BIT数据类型?
10 个解决方案
#1
194
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'开始,当有人指出'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.
最糟糕的是,他们捍卫这个愚蠢的决定,就像他们捍卫'= NULL愚蠢。
#2
37
Nope.
不。
Can use:
可以使用:
IS_COOL NUMBER(1,0)
1 - true
0 - false
--- enjoy Oracle
---享受Oracle
Or use char Y/N as described here
或者使用此处描述的char Y / N.
#3
26
As per Ammoq and kupa's answers, We use number(1) with default of 0 and don't allow nulls.
根据Ammoq和kupa的答案,我们使用数字(1),默认值为0,不允许空值。
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).
不存在类型boolean,但是你可以使用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中有一个布尔类型,但没有一个可以用作列的数据类型。
#7
4
A common space-saving trick is storing boolean values as an Oracle CHAR, rather than NUMBER:
一个常见的节省空间的技巧是将布尔值存储为Oracle CHAR,而不是NUMBER:
#8
3
Just because nobody mentioned it yet: using RAW(1) also seems common practice.
仅仅因为没人提到它:使用RAW(1)似乎也是常见的做法。
#9
3
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
194
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'开始,当有人指出'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.
最糟糕的是,他们捍卫这个愚蠢的决定,就像他们捍卫'= NULL愚蠢。
#2
37
Nope.
不。
Can use:
可以使用:
IS_COOL NUMBER(1,0)
1 - true
0 - false
--- enjoy Oracle
---享受Oracle
Or use char Y/N as described here
或者使用此处描述的char Y / N.
#3
26
As per Ammoq and kupa's answers, We use number(1) with default of 0 and don't allow nulls.
根据Ammoq和kupa的答案,我们使用数字(1),默认值为0,不允许空值。
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).
不存在类型boolean,但是你可以使用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中有一个布尔类型,但没有一个可以用作列的数据类型。
#7
4
A common space-saving trick is storing boolean values as an Oracle CHAR, rather than NUMBER:
一个常见的节省空间的技巧是将布尔值存储为Oracle CHAR,而不是NUMBER:
#8
3
Just because nobody mentioned it yet: using RAW(1) also seems common practice.
仅仅因为没人提到它:使用RAW(1)似乎也是常见的做法。
#9
3
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;