2014-09-30 60 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