插入多行时的虚拟结果

时间:2016-11-24 20:28:22

标签: oracle oracle-sqldeveloper

我最近创建了一个名为Movie_Stars的表。它包含6列:Movie_Number编号唯一,Movie_Title varchar2(30)唯一,Year_Released日期不为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 个答案:

答案 0 :(得分:1)

  1. INSERT ALLSELECT之间有一个错误的分号;这意味着它们是两个不同的陈述,而不是一个陈述。
  2. 您缺少很多用于包装字符串值的引号
  3. 您不能以这种方式插入日期值;您必须使用to_date或使用ANSI标准
  4. 您可以将代码重写为:

    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;