SQL语句出错

时间:2011-10-02 19:23:01

标签: sql oracle

我要做的是创建一个视图,选择empno,ename,deptno将列empno重命名为Employee_ID,ename to Employee,deptno重命名为Department_ID 为什么我有这些问题的任何想法?

SQL> create view DEPT20 AS
2  select empno,ename,deptno (employee_id, employee, Department_ID) from emp
3  where deptno = 20
4  with check option constraint emp_dept_20;
select empno,ename,deptno (employee_id, employee, Department_ID) from emp
                   *
ERROR at line 2:
ORA-00904: "DEPTNO": invalid identifier

我知道它的存在,为什么我会收到错误?

SQL> select empno, ename, deptno from emp;

 EMPNO ENAME          DEPTNO
 ---------- ---------- ----------
  7839 KING               10
  7698 BLAKE              30
  7782 CLARK              10
  7566 JONES              20
  7654 MARTIN             30
  7499 ALLEN              30
  7844 TURNER             30
  7900 JAMES              30
  7521 WARD               30
  7902 FORD               20
  7369 SMITH              20

 EMPNO ENAME          DEPTNO
 ---------- ---------- ----------
  7788 SCOTT              20
  7876 ADAMS              20
  7934 MILLER             10
  8888 Stuttle            40

 15 rows selected.

 SQL>

3 个答案:

答案 0 :(得分:2)

看起来您正在尝试重命名列。我认为您需要像以下一样

select empno as employee_id, ename as employee,deptno as department_id from emp

答案 1 :(得分:2)

如果你试试这个,也许会有所帮助:

SELECT 
  empno as employee_id,
  ename as employee,
  deptno as Department_ID
FROM emp ...

答案 2 :(得分:1)

为什么不尝试这样 -

... select empno as employee_id, ename as employee, deptno as Department_ID 
from emp where Department_ID = 20 ...