Reputation: 27
I am getting a ORA-00923 (FROM keyword not found where expected) error when i run this query in sql*plus.
SELECT EMPLOYEE_ID, FIRST_NAME||' '||LAST_NAME AS FULLNAME
FROM EMPLOYEES
WHERE (JOB_ID, DEPARTMENT_ID)
IN (SELECT JOB_ID, DEPARTMENT_ID FROM JOB_HISTORY)
AND DEPARTMENT_ID=80;
I ran that query in sql developer and guess what, it works without any problem, why I'm getting this error message when I try in sql*plus.
Upvotes: 0
Views: 169
Reputation: 10931
Your query is totally valid and runs in sqlplus exactly as it should:
14:04:01 (41)HR@sandbox> l
1 SELECT EMPLOYEE_ID, FIRST_NAME||' '||LAST_NAME AS FULLNAME
2 FROM EMPLOYEES
3 WHERE (JOB_ID, DEPARTMENT_ID)
4 IN (SELECT JOB_ID, DEPARTMENT_ID FROM JOB_HISTORY)
5* AND DEPARTMENT_ID=80
14:04:05 (41)HR@sandbox> /
34 rows selected.
Elapsed: 00:00:00.01
You encounter ORA-00923 only when you have a syntax error. Like this:
14:04:06 (41)HR@sandbox> ed
Wrote file S:\spool\sandbox\BUF_HR_41.sql
1 SELECT EMPLOYEE_ID, FIRST_NAME||' '||LAST_NAME AS FULLNAME X
2 FROM EMPLOYEES
3 WHERE (JOB_ID, DEPARTMENT_ID)
4 IN (SELECT JOB_ID, DEPARTMENT_ID FROM JOB_HISTORY)
5* AND DEPARTMENT_ID=80
14:05:17 (41)HR@sandbox> /
SELECT EMPLOYEE_ID, FIRST_NAME||' '||LAST_NAME AS FULLNAME X
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
Probably you made one while copying your query from sqldeveloper to sqlplus? Are you sure that your post contains exactly, symbol-to-symbol, the query you're actually trying to execute? I would pay more attention to query text and error message - it usually points at an error, like *
under X
in my example.
Upvotes: 1
Reputation: 5225
SELECT EMPLOYEE_ID, FIRST_NAME || ' ' || LAST_NAME AS FULLNAME
FROM EMPLOYEES
WHERE JOB_ID IN (SELECT JOB_ID
FROM JOB_HISTORY
WHERE DEPARTMENT_ID = 80);
OR
SELECT EMPLOYEE_ID, FIRST_NAME || ' ' || LAST_NAME AS FULLNAME
FROM EMPLOYEES
WHERE JOB_ID IN (SELECT JOB_ID FROM JOB_HISTORY) AND DEPARTMENT_ID = 80;
OR
SELECT EMPLOYEE_ID, FIRST_NAME || ' ' || LAST_NAME AS FULLNAME
FROM EMPLOYEES E
WHERE EXISTS (SELECT NULL
FROM JOB_HISTORY J
WHERE J.JOB_ID = E.JOB_ID)
AND DEPARTMENT_ID = 80;
Upvotes: 1
Reputation: 8431
I don't know what you are trying to achieve but here's a possible solution:
/* Formatted on 10/1/2013 1:50:20 PM (QP5 v5.126.903.23003) */
SELECT EMPLOYEE_ID, FIRST_NAME || ' ' || LAST_NAME AS FULLNAME
FROM EMPLOYEES EMP
JOIN
JOB_HISTORY JH
ON EMP.JOB_ID = JH.JOB_ID AND EMP.DEPARTMENT_ID = JH.DEPARTMENT_ID
WHERE EMP.DEPARTMENT_ID = 80;
Upvotes: 0