我执行以下操作:
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?
删除错误的逗号后,表格已创建。
答案 0 :(得分: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
提出,因为如果它不存在,你可以改变它(但是神秘的是为什么你可以&#39} ;创建它。)
" ORA-00904 ::无效的标识符"表示您使用了表中不存在的列名,例如
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如何响应。
答案 1 :(得分:0)
这应该有效
drop table loan;
create table loan
(
loanno INT not null,
loandate date not null,
loanreturndate date null,
loanreserve number (20) null,
paymentdate date null
);