Oracle:创建视图时SQL命令未正确结束

时间:2018-02-20 10:40:09

标签: sql oracle

我正在尝试在Oracle中进行一些练习,当我尝试创建视图时,我收到此错误:SQL command not properly ended。 我认为这可能是我的错误,我试图直接从官方oracle幻灯片中复制粘贴一些代码:

 CREATE VIEW view_employees
 AS SELECT employee_id emp_id, first_name, last_name, email
 FROM employees
 WHERE employee_id BETWEEN 100 and 124

 SELECT *
 FROM view_employees

但即使修改了create statement添加,我也会遇到同样的错误 CREATE OR REPLACE VIEW

2 个答案:

答案 0 :(得分:2)

如果您按以下方式更改语句,则应该有效:

CREATE VIEW view_employees
  AS SELECT employee_id emp_id,first_name, last_name, email
  FROM employees
  WHERE employee_id BETWEEN 100 and 124;

SELECT *
FROM view_employees;

您需要使用CREATE VIEW;终止/。否则Oracle无法识别CREATE VIEW语句已结束,因此当它看到SELECT时它确定出错了。

答案 1 :(得分:-1)

试试这个......

CREATE OR REPLACE VIEW view_employees
     AS SELECT employee_id emp_id, first_name, last_name, email
     FROM employees
     WHERE emp_id BETWEEN 100 and 124;

     SELECT *
     FROM view_employees;