2014-09-30 59 views
1

我一直在尝试使用约束来创建表,因为这是我们的教授想要做的事情。但是,当我这样做的时候,在没有之前我会犯很多错误。我的代码如下所示:ORA-00942:尝试使用约束时表或视图不存在

DROP TABLE movie CASCADE CONSTRAINTS; 
CREATE TABLE movie(
movie_id NUMBER(5), 
title VARCHAR2(45) NOT NULL, 
description VARCHAR2(250) NOT NULL, 
released_by NUMBER(3) NOT NULL, 
released_on DATE NOT NULL 
constraint movie_pk primary key (movie_id)); 

INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES ('1', 'Edge of Tomorrow', 'Lieutenant Colonel Bill Cage is a skilled tactician who has honed his abilities through his experiences as a soldier. However, there is still much he can learn, and soon he is going to get his chance.', '1', '07-OCT-2014'); 

INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('2', 'Captain America: Winter Soldier', 'Steve Rogers is finding it difficult to adjust to living life in the contemporary world. He is working for S.H.I.E.L.D. and begins to suspect a mystery is brewing there.', '2', '09-SEP-2014'); 

INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('3', 'Fed Up', 'America’s problem with obesity is caused by our inactivity. Or is it? Katie Couric and Stephanie Soechtig tempt us to restructure our beliefs about the American diet, through this thought-provoking expose.', '3', '09-SEP-2014'); 

INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, its the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014'); 

INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('5', 'Neighbors', 'New parents Mac and Kelly settle into domesticity in a quiet neighborhood. The tranquility they have been afforded ceases to exist when a fraternity moves into the house next door.', '2', '14-SEP-2014'); 

COMMIT; 

的出,从我把运行在Oracle中的代码如下:

SQL> @test.sql 
DROP TABLE movie CASCADE CONSTRAINTS 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 


constraint movie_pk primary key (movie_id)) 
           * 
ERROR at line 7: 
ORA-00907: missing right parenthesis 


INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES ('1', 'Edge of Tomorrow', 'Lieutenant Colonel Bill Cage is a skilled tactician who has honed his abilities through his experiences as a soldier. However, there is still much he can learn, and soon he is going to get his chance.', '1', '07-OCT-2014') 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 


INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('2', 'Captain America: Winter Soldier', 'Steve Rogers is finding it difficult to adjust to living life in the contemporary world. He is working for S.H.I.E.L.D. and begins to suspect a mystery is brewing there.', '2', '09-SEP-2014') 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 


INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('3', 'Fed Up', 'Americas problem with obesity is caused by our inactivity. Or is it? Katie Couric and Stephanie Soechtig tempt us to restructure our beliefs about the American diet, through this thought-provoking expose.', '3', '09-SEP-2014') 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 


INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, its the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014') 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 


INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('5', 'Neighbors', 'New parents Mac and Kelly settle into domesticity in a quiet neighborhood. The tranquility they have been afforded ceases to exist when a fraternity moves into the house next door.', '2', '14-SEP-2014') 
      * 
ERROR at line 1: 
ORA-00942: table or view does not exist 



Commit complete. 

正如你可以看到有这个代码中的多个错误,只是从我加入限制。任何帮助,将不胜感激。

回答

3

缺少一个逗号:

released_on DATE NOT NULL, 
         ^
constraint movie_pk primary key (movie_id)); 
+0

它总是简单的东西。谢谢 – 2014-09-30 00:29:06

+0

欢迎您光临! – 2014-09-30 00:29:40