为什么这个 CREATE 命令没有运行?

发布于 2025-01-10 18:24:31 字数 2070 浏览 0 评论 0原文

这是脚本的一部分,整个脚本运行没有错误。我按照脚本进行了一些细微的更改,只是更改了名称等,并丢弃了一些命令,例如“创建或替换强制视图”、序列。

CREATE TABLE  "EMPLOYEES"
   ("EMPLOYEE_ID" NUMBER(6,0),
    "FIRST_NAME" VARCHAR2(20),
    "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE,
    "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE,
    "PHONE_NUMBER" VARCHAR2(20),
    "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE,
    "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE,
    "SALARY" NUMBER(8,2),
    "COMMISSION_PCT" NUMBER(2,2),
    "MANAGER_ID" NUMBER(6,0),
    "DEPARTMENT_ID" NUMBER(4,0),
        "BONUS" VARCHAR2(5),
     CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE,
     CONSTRAINT "EMP_ID_PK" PRIMARY KEY ("EMPLOYEE_ID")
  USING INDEX  ENABLE,
     CONSTRAINT "EMP_EMAIL_UK" UNIQUE ("EMAIL")
  USING INDEX  ENABLE
  );

这是我从那里编辑的“CREATE TABLE”命令之一。

CREATE TABLE  "PRODUCT"
   ("Prod_ID" VARCHAR2(10) CONSTRAINT "Prod_ID_NN" NOT NULL ENABLE,
    "Prod_Price" NUMBER(3,2) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
    "Prod_Avail" VARCHAR2(20) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
    "Prod_MDate" DATE CONSTRAINT "Prod_MDate_NN" NOT NULL ENABLE,
    "Prod_EDate" DATE CONSTRAINT "Prod_EDate_NN" NOT NULL ENABLE,
    "Cust_ID" NUMBER(4,0),
    "Sto_ID" VARCHAR(8) CONSTRAINT "Sto_ID_NN" NOT NULL ENABLE,
    "Sup_ID" VARCHAR(10),
    CONSTRAINT "Prod_ID_PK" PRIMARY KEY ("Prod_ID")
    CONSTRAINT "Prod_Date_Interval" CHECK (Prod_EDate > Prod_MDate) ENABLE,
    USING INDEX  ENABLE
   );

错误就出来了; ORA-00907:缺少右括号

ORA-06512:位于“SYS.WWV_DBMS_SQL_APEX_210200”,第 673 行

ORA-06512:位于“SYS.DBMS_SYS_SQL”,第 1658 行

ORA-06512:位于“SYS.WWV_DBMS_SQL_APEX_210200”,第 659 行

ORA-06512: 在“APEX_210200.WWV_FLOW_DYNAMIC_EXEC”,第 1829 行

“Prod_Avail”VARCHAR2(20) CONSTRAINT“Prod_Price_NN”NOT NULL ENABLE, “Prod_MDate”日期约束“Prod_MDate_NN”NOT NULL 启用, “Prod_EDate”日期约束“Prod_EDate_NN”非空启用,

“Cust_ID”NUMBER(4,0),

“Sto_ID”VARCHAR(8)约束“Sto_ID_NN”非空启用,

This is a part of a script which the whole script runs without errors. I followed the script and made minor changes, just by changing names, etc and discarded few commands like 'create or replace force view', sequences.

CREATE TABLE  "EMPLOYEES"
   ("EMPLOYEE_ID" NUMBER(6,0),
    "FIRST_NAME" VARCHAR2(20),
    "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE,
    "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE,
    "PHONE_NUMBER" VARCHAR2(20),
    "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE,
    "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE,
    "SALARY" NUMBER(8,2),
    "COMMISSION_PCT" NUMBER(2,2),
    "MANAGER_ID" NUMBER(6,0),
    "DEPARTMENT_ID" NUMBER(4,0),
        "BONUS" VARCHAR2(5),
     CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE,
     CONSTRAINT "EMP_ID_PK" PRIMARY KEY ("EMPLOYEE_ID")
  USING INDEX  ENABLE,
     CONSTRAINT "EMP_EMAIL_UK" UNIQUE ("EMAIL")
  USING INDEX  ENABLE
  );

This is one of the 'CREATE TABLE' commands that I edited from there.

CREATE TABLE  "PRODUCT"
   ("Prod_ID" VARCHAR2(10) CONSTRAINT "Prod_ID_NN" NOT NULL ENABLE,
    "Prod_Price" NUMBER(3,2) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
    "Prod_Avail" VARCHAR2(20) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
    "Prod_MDate" DATE CONSTRAINT "Prod_MDate_NN" NOT NULL ENABLE,
    "Prod_EDate" DATE CONSTRAINT "Prod_EDate_NN" NOT NULL ENABLE,
    "Cust_ID" NUMBER(4,0),
    "Sto_ID" VARCHAR(8) CONSTRAINT "Sto_ID_NN" NOT NULL ENABLE,
    "Sup_ID" VARCHAR(10),
    CONSTRAINT "Prod_ID_PK" PRIMARY KEY ("Prod_ID")
    CONSTRAINT "Prod_Date_Interval" CHECK (Prod_EDate > Prod_MDate) ENABLE,
    USING INDEX  ENABLE
   );

Errors came out;
ORA-00907: missing right parenthesis

ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 673

ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658

ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 659

ORA-06512: at "APEX_210200.WWV_FLOW_DYNAMIC_EXEC", line 1829

"Prod_Avail" VARCHAR2(20) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
"Prod_MDate" DATE CONSTRAINT "Prod_MDate_NN" NOT NULL ENABLE,
"Prod_EDate" DATE CONSTRAINT "Prod_EDate_NN" NOT NULL ENABLE,

"Cust_ID" NUMBER(4,0),

"Sto_ID" VARCHAR(8) CONSTRAINT "Sto_ID_NN" NOT NULL ENABLE,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2025-01-17 18:24:31

我建议您在使用 Oracle 时忘记双引号。他们没有什么好处,只有问题。

当您修复错误,

  • 将混合大小写的列名括在约束中的双引号中时
  • ,使用唯一约束名称
  • 重新排列使用索引启用

,那么它有效

SQL> CREATE TABLE "PRODUCT"
  2  (
  3     "Prod_ID"      VARCHAR2 (10) CONSTRAINT "Prod_ID_NN" NOT NULL ENABLE,
  4     "Prod_Price"   NUMBER (3, 2) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
  5     "Prod_Avail"   VARCHAR2 (20) CONSTRAINT "Prod_Avail_NN" NOT NULL ENABLE,
  6     "Prod_MDate"   DATE CONSTRAINT "Prod_MDate_NN" NOT NULL ENABLE,
  7     "Prod_EDate"   DATE CONSTRAINT "Prod_EDate_NN" NOT NULL ENABLE,
  8     "Cust_ID"      NUMBER (4, 0),
  9     "Sto_ID"       VARCHAR (8) CONSTRAINT "Sto_ID_NN" NOT NULL ENABLE,
 10     "Sup_ID"       VARCHAR (10),
 11     CONSTRAINT "Prod_ID_PK" PRIMARY KEY ("Prod_ID") USING INDEX ENABLE,
 12     CONSTRAINT "Prod_Date_Interval" CHECK ("Prod_EDate" > "Prod_MDate") ENABLE
 13  );

Table created.

SQL>

但是 - 再一次 - 我不会就那样做。我该怎么做呢?像这样:

SQL> CREATE TABLE product
  2  (
  3     prod_id      VARCHAR2 (10) CONSTRAINT prod_id_nn NOT NULL ENABLE,
  4     prod_price   NUMBER (3, 2) CONSTRAINT prod_price_nn NOT NULL ENABLE,
  5     prod_avail   VARCHAR2 (20) CONSTRAINT prod_avail_nn NOT NULL ENABLE,
  6     prod_mdate   DATE CONSTRAINT prod_mdate_nn NOT NULL ENABLE,
  7     prod_edate   DATE CONSTRAINT prod_edate_nn NOT NULL ENABLE,
  8     cust_id      NUMBER (4, 0),
  9     sto_id       VARCHAR (8) CONSTRAINT sto_id_nn NOT NULL ENABLE,
 10     sup_id       VARCHAR (10),
 11     CONSTRAINT prod_id_pk PRIMARY KEY (prod_id) USING INDEX ENABLE,
 12     CONSTRAINT prod_date_interval CHECK (prod_edate > prod_mdate) ENABLE
 13  );

Table created.

SQL>

I'd suggest you to forget about double quotes while working with Oracle. Nothing good in them, only problems.

When you fix errors

  • enclosing column names with mixed case into double quotes in constraints
  • use unique constraint names
  • rearrange using index enable

then it works:

SQL> CREATE TABLE "PRODUCT"
  2  (
  3     "Prod_ID"      VARCHAR2 (10) CONSTRAINT "Prod_ID_NN" NOT NULL ENABLE,
  4     "Prod_Price"   NUMBER (3, 2) CONSTRAINT "Prod_Price_NN" NOT NULL ENABLE,
  5     "Prod_Avail"   VARCHAR2 (20) CONSTRAINT "Prod_Avail_NN" NOT NULL ENABLE,
  6     "Prod_MDate"   DATE CONSTRAINT "Prod_MDate_NN" NOT NULL ENABLE,
  7     "Prod_EDate"   DATE CONSTRAINT "Prod_EDate_NN" NOT NULL ENABLE,
  8     "Cust_ID"      NUMBER (4, 0),
  9     "Sto_ID"       VARCHAR (8) CONSTRAINT "Sto_ID_NN" NOT NULL ENABLE,
 10     "Sup_ID"       VARCHAR (10),
 11     CONSTRAINT "Prod_ID_PK" PRIMARY KEY ("Prod_ID") USING INDEX ENABLE,
 12     CONSTRAINT "Prod_Date_Interval" CHECK ("Prod_EDate" > "Prod_MDate") ENABLE
 13  );

Table created.

SQL>

But - once again - I wouldn't do it that way. How would I do it? Lke this:

SQL> CREATE TABLE product
  2  (
  3     prod_id      VARCHAR2 (10) CONSTRAINT prod_id_nn NOT NULL ENABLE,
  4     prod_price   NUMBER (3, 2) CONSTRAINT prod_price_nn NOT NULL ENABLE,
  5     prod_avail   VARCHAR2 (20) CONSTRAINT prod_avail_nn NOT NULL ENABLE,
  6     prod_mdate   DATE CONSTRAINT prod_mdate_nn NOT NULL ENABLE,
  7     prod_edate   DATE CONSTRAINT prod_edate_nn NOT NULL ENABLE,
  8     cust_id      NUMBER (4, 0),
  9     sto_id       VARCHAR (8) CONSTRAINT sto_id_nn NOT NULL ENABLE,
 10     sup_id       VARCHAR (10),
 11     CONSTRAINT prod_id_pk PRIMARY KEY (prod_id) USING INDEX ENABLE,
 12     CONSTRAINT prod_date_interval CHECK (prod_edate > prod_mdate) ENABLE
 13  );

Table created.

SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文