
3

Error with an SQL statement
source link: https://www.codesd.com/item/error-with-an-sql-statement.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Error with an SQL statement
advertisements
What I am trying to do is create a view that selects empno, ename, deptno renames the columns empno to Employee_ID, ename to Employee, Deptno to Department_ID Any ideas to why I have these problems?
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
I know its there so why do I get the error?
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>
why don't you try like this -
... select empno as employee_id, ename as employee, deptno as Department_ID
from emp where Department_ID = 20 ...
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK