【问题标题】:Missing right parenthesis after (or before) default 0, Oracle在默认 0 之后(或之前)缺少右括号,Oracle
【发布时间】:2019-05-22 06:23:10
【问题描述】:

我正在尝试使用 oracle SQL 创建一个表,该表的两列应具有默认值,不应为 NULL。

我收到了您可以在下面看到的错误,但我无法理解它,因为那里没有括号要关闭!!!!

CREATE TABLE ENCUENTROS (
  2  elocal constraint clave_extrana_equipos references equipos(code) not null enable,
  3  evisitante constraint clave_extrana_equipos references equipos(code) not null enable,
  4  fecha date,
  5  plocal number constraint plocal_mayor_cero check (plocal > 0) default 0 not null enable,
  6  pvisitante number constraint pvisitante_mayor_cero check (pvisitante > 0) default 0 not null enable);
plocal number constraint plocal_mayor_cero check (plocal > 0) default 0 not null enable,
                                                              *
ERROR at line 5:
ORA-00907: missing right parenthesis

错误已解决:

【问题讨论】:

  • 不知道这是否是错误,但您的检查约束 plocal > 0 与您的默认值 0 相矛盾。
  • 看一眼the online Oracle documentation (link) 会发现inline constraint 子句位于列定义的末尾,在defaultnot null 声明之后。

标签: sql oracle oracle-sqldeveloper oracle12c


【解决方案1】:

这段代码对我有用:

create table encuentros (
  elocal number not null 
    constraint clave_extrana_equipos_1 references equipos(code) enable,
  evisitante number not null 
    constraint clave_extrana_equipos_2 references equipos(code) enable,
  fecha date,
  plocal number default 0 not null 
    constraint plocal_mayor_cero check (plocal >= 0)  enable,
  pvisitante number default 0 not null 
    constraint pvisitante_mayor_cero check (pvisitante >= 0) enable);

有几个问题:

  • 名称clave_extrana_equipos 用于约束被使用了两次。使用两个不同的名称,
  • elocalevisitante 没有指定类型,
  • 在类型说明之后、约束之前写入default 0 not null

编辑:

@APC 注意到这里不需要前两列的类型规范。

【讨论】:

  • "列 elocalevisitante 没有指定类型," 当列有外键时这是合法的:列继承了被引用主的数据类型钥匙。事实上,它不仅合法而且更安全。
  • @APC 我能够在不指定列类型的情况下创建表。问题已更新。
猜你喜欢
  • 2021-11-10
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 2021-07-29
相关资源
最近更新 更多