【问题标题】:SQL : can not create a tableSQL:无法创建表
【发布时间】:2018-04-28 10:17:22
【问题描述】:

我执行以下操作:

use oracle developer

create table loan 
(
        barcode                 number (20) not null ,
        borrowernumber          number (7) ,
        loancurrentdate         date ,
        loanreturndate          date ,
        loanreserveorder        number (20) ,
        paymentdate             date ,
        borrower_borrowernumber number not null
);

alter table loan add constraint loan_pk primary key (barcode) ;

无法创建表,然后更改它...

create table loan 
(
    loanno                  INT not null,
    loandate                date not null,
    loanreturndate          date null,
    loanreserve             number (20) null,
    paymentdate             date null,
);

alter table loan add constraint loan_pk primary key (loanno) ;

我收到以下错误。为什么我会得到这个?

错误报告
SQL 错误:ORA-00942:表或视图不存在
00942. 00000 - “表或视图不存在”

它还显示“无效标识符”

错误报告:

SQL 错误:ORA-00904: : 标识符无效
00904. 00000 - "%s: 无效标识符"

或者我应该删除付款日期吗?


删除错误的逗号后,表就创建好了。

【问题讨论】:

  • “不起作用”没有帮助。你有错误吗?如果是这样,你的错误是什么。另外,标记您正在使用的数据库。
  • 我不太了解行动时间表。还有什么时候会出现这个错误?
  • paymentdate date null, 后面的逗号有误,应该删除它
  • use oracle developer 那是一个以空格为分隔符的Table_Name吗?
  • 尝试在表声明后添加语句GO;。也可以试试/

标签: sql oracle


【解决方案1】:

您发布的两个示例都是正确的(除了第二个 CREATE TABLE 语句末尾的多余逗号)。这是 SQL*Plus 示例,但是 - 正如 SQL Developer 模拟它很好,我相信它们也应该在那里工作得很好。

第一个:

SQL> create table loan
  2  (
  3          barcode                 number (20) not null ,
  4          borrowernumber          number (7) ,
  5          loancurrentdate         date ,
  6          loanreturndate          date ,
  7          loanreserveorder        number (20) ,
  8          paymentdate             date ,
  9          borrower_borrowernumber number not null
 10  );

Table created.

SQL> alter table loan add constraint loan_pk primary key (barcode) ;

Table altered.

第二个:

SQL> drop table loan;

Table dropped.

SQL> create table loan
  2  (
  3      loanno                  INT not null,
  4      loandate                date not null,
  5      loanreturndate          date null,
  6      loanreserve             number (20) null,
  7      paymentdate             date null
  8  );

Table created.

SQL> alter table loan add constraint loan_pk primary key (loanno) ;

Table altered.

SQL>

在第一个 CREATE TABLE 之后说“无法创建表,然后更改它...”到底是什么意思?有什么错误吗?如果有,是哪一个?

“ORA-00942:表或视图不存在”可能是由ALTER TABLE 提出的,因为如果它不存在,您就无法更改它(但谜团在于 为什么你不能创建它)。

“ORA-00904::invalid identifier”表示你使用了表中不存在的列名,如

SQL> alter table loan modify xxx number;
alter table loan modify xxx number
                        *
ERROR at line 1:
ORA-00904: "XXX": invalid identifier

如果可能,请像我一样做 - 复制/粘贴 SQL*Plus 会话,以便我们可以看到您做了什么以及 Oracle 是如何响应的。

【讨论】:

  • 创建的表。谢谢。
【解决方案2】:

这应该可行

drop table loan;
create table loan 
(
    loanno                  INT not null,
    loandate                date not null,
    loanreturndate          date null,
    loanreserve             number (20) null,
    paymentdate             date null
);

【讨论】:

    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 2015-02-04
    • 2011-12-13
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多