2016-11-24 72 views
-1

我最近創建了一個名爲Movie_Stars的表。它包含6列:Movie_Number number unique,Movie_Title varchar2(30)unique,Year_Released date not null,First_Name varchar2(15),Last_Name varchar2(15)和Movie_Category varchar2(15)。我需要插入下面的值到表:插入多行時的虛擬結果

insert all 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (1, 'New York Stories', 'January 1 1984', Nick, Nolte, Drama) 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category)  
      values (2, 'Speed', '1999, FEB 12', Keanu, Reeves, Action) 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (3, 'Superman', '1982, MAR 7', Chris, Reeve, Action) 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (4, 'Ice Age', '2002, April 2', Chris, Rock, Cartoon) 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (5, 'Bowfinger', '2001, August 03', Eddie, Murphy, Comedy); 
select * from dual; 

然而,當我跑的代碼,它返回的結果如下:

DUMMY 
----- 
1 x 

這是什麼意思?如何解決?

+1

'從dual'選擇*? – Aleksej

回答

1
  1. INSERT ALLSELECT之間有錯誤的分號;這意味着它們是兩種不同的陳述,而不是單一的陳述。
  2. 您錯過了許多報價來包裝您的字符串值
  3. 您無法以此方式插入日期值;你必須使用一個to_date或使用ANSI標準

您可以重寫代碼爲:

insert all 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (1, 'New York Stories', date '1984-01-01', 'Nick', 'Nolte', 'Drama') 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category)  
      values (2, 'Speed', date '1992-02-12', 'Keanu', 'Reeves', 'Action') 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (3, 'Superman', date '1982-03-07', 'Chris', 'Reeve', 'Action') 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (4, 'Ice Age', to_date ('02/04/2002', 'dd/mm/yyyy'), 'Chris', 'Rock', 'Cartoon') 
into movie_stars (movie_number, movie_title, year_released, first_name, last_name, movie_category) 
      values (5, 'Bowfinger', date '2001-08-03', 'Eddie', 'Murphy', 'Comedy') 
select * from dual; 
+0

謝謝你Aleksej!我以爲我只需要日期和多個單詞的引號。另一件事,當我稍後檢索數據以加倍時,請檢查,即使使用to_date函數,第4行的日期格式也不會更改。 – Tim

+0

它們只是兩種不同的寫日期值的方法,但結果是絕對相同的;如果你需要一個特定的格式,比如說你必須從一個輸入字符串中獲得一個日期,你可以使用to_date和適當的格式掩碼;如果你只需要寫一個日期值,你可以使用更簡單的(恕我直言)ANSI方式 – Aleksej

+0

明白了。謝謝! – Tim