您的查詢完全有效,完全按照它應該在sqlplus中運行:
14:04:01 (41)[email protected]> 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)[email protected]>/
34 rows selected.
Elapsed: 00:00:00.01
只有當您遇到語法錯誤時纔會遇到ORA-00923。像這樣:
14:04:06 (41)[email protected]> 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)[email protected]>/
SELECT EMPLOYEE_ID, FIRST_NAME||' '||LAST_NAME AS FULLNAME X
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
可能你在從sqldeveloper複製你的查詢到sqlplus時做了一個?你確定你的文章中包含了符號 - 符號嗎?你實際上試圖執行的查詢嗎?我會更加關注查詢文本和錯誤信息 - 它通常指向一個錯誤,例如*
,在我的示例中爲X
。
只是一個查詢:你爲什麼在你的where子句中使用'DEPARTMENT_ID'兩次?如果'DEPARTMENT_ID'必須是'80',那麼您可以在內部查詢中檢索'job_id'? – heretolearn
在SQL Plus客戶端中,您可以將查詢分解爲多行來隔離問題。 – heretolearn
我知道,但我只是練習子查詢主題。我沒有這本書的相同數據庫,所以我讓這個查詢來練習。 xDDDDD –