Oracle 23.26SQLLab-verified · 2026-11-29

ORA-02000: missing keyword (THEN, ON or USING, AS)

A required keyword is missing, and the message tells you which one (THEN, ON or USING, AS).

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-02000: missing THEN keyword

Jump to a cause

  1. 01CASE WHEN without THEN
  2. 02JOIN with the join condition in WHERE instead of ON
  3. 03CREATE VIEW without AS before the SELECT
  4. 04CAST without AS between the value and the type

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-29 · container image gvenzl/oracle-free:23-slim

ORA-02000 names the keyword the parser expected: missing THEN keyword, missing ON or USING keyword, missing AS keyword. The * under the line shows where it expected that keyword, so the fix is usually to insert it right before that position.

All four cases below were run on Oracle AI Database 26ai Free (23.26). The Korean and Japanese sessions give the same keyword in the localized message.

01CASE WHEN without THEN

In CASE status WHEN 'N' 'New', the result 'New' follows the WHEN value directly. Oracle expected THEN there, and the * points at 'New'.

Setup
Setuprun as lab_a
CREATE TABLE orders (id NUMBER PRIMARY KEY, status VARCHAR2(1));
INSERT INTO orders VALUES (1, 'N');
INSERT INTO orders VALUES (2, 'S');
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT id,
       CASE status WHEN 'N' 'New' WHEN 'S' 'Shipped' END AS label
FROM orders;
✕ ERROR
       CASE status WHEN 'N' 'New' WHEN 'S' 'Shipped' END AS label
                            *
ERROR at line 2:
ORA-02000: missing THEN keyword
Help: https://docs.oracle.com/error-help/db/ora-02000/
Checkrun as lab_a
SELECT status, COUNT(*) AS cnt FROM orders GROUP BY status ORDER BY status;
OUTPUT
STATUS                                CNT
------------------------------ ----------
N                                       1
S                                       1

2 rows selected.

Write WHEN value THEN result for every branch. After adding THEN, rows 1 and 2 return New and Shipped.

After the fixrun as lab_a
SELECT id,
       CASE status WHEN 'N' THEN 'New' WHEN 'S' THEN 'Shipped' END AS label
FROM orders
ORDER BY id;
✓ SUCCESS
        ID LABEL
---------- -------
         1 New
         2 Shipped

2 rows selected.

02JOIN with the join condition in WHERE instead of ON

ANSI JOIN needs its condition right after the table: ON … or USING (…). Here the condition is written in WHERE, so the parser reaches WHERE while still waiting for ON, and the * points at WHERE.

Setup
Setuprun as lab_a
CREATE TABLE dept (deptno NUMBER PRIMARY KEY, dname VARCHAR2(20));
CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(20), deptno NUMBER);
INSERT INTO dept VALUES (10, 'SALES');
INSERT INTO emp VALUES (1, 'KIM', 10);
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT e.ename, d.dname
FROM emp e JOIN dept d
WHERE e.deptno = d.deptno;
✕ ERROR
WHERE e.deptno = d.deptno
*
ERROR at line 3:
ORA-02000: missing ON or USING keyword
Help: https://docs.oracle.com/error-help/db/ora-02000/
Checkrun as lab_a
SELECT table_name, column_name FROM user_tab_columns WHERE column_name = 'DEPTNO' ORDER BY table_name;
OUTPUT
TABLE_NAME                     COLUMN_NAME
------------------------------ ------------------------------
DEPT                           DEPTNO
EMP                            DEPTNO

2 rows selected.

Move the condition to ON e.deptno = d.deptno. Both tables have a DEPTNO column, so USING (deptno) would also fit. If you really want every combination, write CROSS JOIN.

After the fixrun as lab_a
SELECT e.ename, d.dname
FROM emp e JOIN dept d ON e.deptno = d.deptno;
✓ SUCCESS
ENAME                DNAME
-------------------- --------------------
KIM                  SALES

1 row selected.

03CREATE VIEW without AS before the SELECT

CREATE OR REPLACE VIEW v_emp must be followed by AS and then the query. Without it the parser hits SELECT and stops. No view is created (user_views returns no rows).

Setup
Setuprun as lab_a
CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(20), sal NUMBER);
INSERT INTO emp VALUES (1, 'KIM', 3000);
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.
Reproducerun as lab_a
CREATE OR REPLACE VIEW v_emp
SELECT empno, ename FROM emp;
✕ ERROR
SELECT empno, ename FROM emp
*
ERROR at line 2:
ORA-02000: missing AS keyword
Help: https://docs.oracle.com/error-help/db/ora-02000/
Checkrun as lab_a
SELECT view_name FROM user_views;
OUTPUT
no rows selected

Add AS after the view name. The view is created and returns the row from emp.

After the fixrun as lab_a
CREATE OR REPLACE VIEW v_emp AS
SELECT empno, ename FROM emp;
SELECT * FROM v_emp;
✓ SUCCESS
View created.


     EMPNO ENAME
---------- --------------------
         1 KIM

1 row selected.

04CAST without AS between the value and the type

CAST(expr AS type) requires AS. CAST('20261129' DATE) skips it, and the * points at DATE.

Reproducerun as lab_a
SELECT CAST('20261129' DATE) FROM dual;
✕ ERROR
SELECT CAST('20261129' DATE) FROM dual
                       *
ERROR at line 1:
ORA-02000: missing AS keyword
Help: https://docs.oracle.com/error-help/db/ora-02000/
Checkrun as lab_a
SELECT TO_DATE('20261129', 'YYYYMMDD') AS d FROM dual;
OUTPUT
D
------------------
29-NOV-26

1 row selected.

Write CAST(expr AS type). To turn a string like '20261129' into a date, use TO_DATE with a format mask, as in the check step. Converted back to text with CAST, the date shows in the session format (29-NOV-26), and CAST('123' AS NUMBER) + 1 returns 124.

After the fixrun as lab_a
SELECT CAST(TO_DATE('20261129', 'YYYYMMDD') AS VARCHAR2(10)) AS d1,
       CAST('123' AS NUMBER) + 1 AS n1
FROM dual;
✓ SUCCESS
D1                 N1
---------- ----------
29-NOV-26         124

1 row selected.

FAQ

What does ORA-02000 missing THEN keyword mean?

A CASE expression has a WHEN branch without THEN. Every branch needs WHEN value THEN result.

How do I fix ORA-02000 missing ON or USING keyword?

A JOIN has no join condition. Add ON (or USING) right after the joined table. Use CROSS JOIN if you want all combinations.

Why do I get ORA-02000 missing AS keyword?

Common places are CREATE VIEW name AS SELECT … and CAST(expr AS type). Add AS where the * points.

How do I find where the keyword is missing?

Look at the * under the line in SQL*Plus. The keyword named in the message belongs just before that position.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0