SQL 在 Oracle 中创建布尔属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14731971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create boolean attribute in Oracle?
提问by Cristian Holdunu
I have to create a table in Oracle and one column I have to make it of Boolean type. Can you please tell me how can I do that? I have searched on the internet but I couldn't find a clear answer.
我必须在 Oracle 中创建一个表,并且必须将一列设为布尔类型。你能告诉我我该怎么做吗?我在互联网上搜索过,但找不到明确的答案。
回答by Rapha?l Althaus
There is no BOOLEAN datatype in SQL. But we can represent it like this:
SQL 中没有 BOOLEAN 数据类型。但是我们可以这样表示:
CREATE TABLE tt
(test NUMBER(1) NOT NULL CHECK (test in (0,1)))
回答by Emil Vikstr?m
Check out CREATE TYPEfor Oracle.
查看Oracle 的CREATE TYPE。
In some databases it is possible to define your own boolean data type (this does notwork in Oracle, I'm told, but it illustrates the idea):
在一些数据库中,可以定义自己的布尔数据类型(这并不会在甲骨文工作,有人告诉我,但它说明的想法):
CREATE DOMAIN BOOLEAN
AS NUMBER(1)
NOT NULL
CHECK (value IN (0,1))
This can be used as any other type for table columns.
这可以用作表列的任何其他类型。
回答by Daniel Hilgarth
There is no boolean data type. You have to use NUMBER(1)
.
没有布尔数据类型。你必须使用NUMBER(1)
.
回答by Art
Read about Virtual Column in Oracle doc and use numbers as suggested by others: 0-false, 1-true. No BOOLEAN datatype in CREATE table in Oracle.
阅读 Oracle 文档中的 Virtual Column 并使用其他人建议的数字:0-false,1-true。Oracle 的 CREATE 表中没有 BOOLEAN 数据类型。