ORA-00936: missing expression
ORA-00936: missing expressionOracle expected a column, value or condition, but found nothing there.
Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-12
ORA-00936 means the parser reached a place where an expression must be, and the next thing was a keyword or the end of the statement. It is almost always a leftover from editing: a comma, an AND, or an empty variable.
The * under the error points to the word right after the gap, not to the gap itself. Look at the line just before the marked word.
Causes and fixes
1A comma left at the end of the SELECT list
After removing the last column, the comma after name stayed. Oracle then expects one more column, finds FROM, and marks FROM emp at line 3.
Remove the comma after the last column. The same query without it returned all 3 rows.
Setup
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10);
INSERT INTO emp VALUES (2, 'Lee', 10);
INSERT INTO emp VALUES (3, 'Park', 20);
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT emp_id,
name,
FROM emp; FROM emp
*
ERROR at line 3:
ORA-00936: missing expression
Help: https://docs.oracle.com/error-help/db/ora-00936/SELECT column_name FROM user_tab_columns WHERE table_name = 'EMP' ORDER BY column_id;COLUMN_NAME
------------------------------
EMP_ID
NAME
DEPT_ID
3 rows selected.Writing commas at the start of each line (, name) makes this mistake easier to see when you delete or comment out a column.
SELECT emp_id,
name
FROM emp
ORDER BY emp_id; EMP_ID NAME
---------- ------------------------------
1 Kim
2 Lee
3 Park
3 rows selected.2Commenting out the first WHERE condition leaves WHERE AND
With -- dept_id = 10 commented out, the statement becomes WHERE AND name LIKE 'K%'. There is no condition between WHERE and AND, so the error points at AND on line 4.
Start the WHERE clause with WHERE 1 = 1 and put AND in front of every real condition. Then any condition line can be commented out. With that change the query returned 1 row (Kim).
Setup
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10);
INSERT INTO emp VALUES (2, 'Lee', 10);
INSERT INTO emp VALUES (3, 'Park', 20);
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT emp_id, name
FROM emp
WHERE -- dept_id = 10
AND name LIKE 'K%'; AND name LIKE 'K%'
*
ERROR at line 4:
ORA-00936: missing expression
Help: https://docs.oracle.com/error-help/db/ora-00936/SELECT COUNT(*) AS cnt FROM emp WHERE 1 = 1; CNT
----------
3
1 row selected.WHERE 1 = 1 is always true, so it does not change the result. It only gives the following AND lines something to attach to.
SELECT emp_id, name
FROM emp
WHERE 1 = 1
-- AND dept_id = 10
AND name LIKE 'K%'; EMP_ID NAME
---------- ------------------------------
1 Kim
1 row selected.3Dynamic SQL is built by concatenating a variable that is NULL
'... WHERE dept_id = ' || v_dept with v_dept NULL produces SELECT COUNT(*) FROM emp WHERE dept_id = — nothing after =. Printing the string before running it showed exactly that. In PL/SQL the error comes with ORA-06512 and the line of EXECUTE IMMEDIATE.
Use a bind variable instead: WHERE dept_id = :d with USING v_dept. The statement text no longer changes, so it always parses. With NULL the count was 0, with 10 it was 2.
Setup
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10);
INSERT INTO emp VALUES (2, 'Lee', 10);
INSERT INTO emp VALUES (3, 'Park', 20);
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
v_dept NUMBER; -- value not passed: NULL
v_cnt NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE dept_id = ' || v_dept INTO v_cnt;
DBMS_OUTPUT.PUT_LINE('count = ' || v_cnt);
END;
/DECLARE
*
ERROR at line 1:
ORA-00936: missing expression
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-00936/SET SERVEROUTPUT ON
DECLARE
v_dept NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('[' || 'SELECT COUNT(*) FROM emp WHERE dept_id = ' || v_dept || ']');
END;
/[SELECT COUNT(*) FROM emp WHERE dept_id = ]
PL/SQL procedure successfully completed.When a dynamic SQL fails, print the final string with DBMS_OUTPUT first. The missing part is usually obvious once you see it.
SET SERVEROUTPUT ON
DECLARE
v_dept NUMBER;
v_cnt NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE dept_id = :d' INTO v_cnt USING v_dept;
DBMS_OUTPUT.PUT_LINE('NULL -> count = ' || v_cnt);
v_dept := 10;
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE dept_id = :d' INTO v_cnt USING v_dept;
DBMS_OUTPUT.PUT_LINE('10 -> count = ' || v_cnt);
END;
/NULL -> count = 0
10 -> count = 2
PL/SQL procedure successfully completed.FAQ
Why does ORA-00936 point at FROM?
The * marks where Oracle noticed the problem, which is the word after the gap. If it points at FROM, check the end of the SELECT list for a trailing comma.
How do I find the missing expression in a long query?
Read the line before the marked word and look for a comma, AND, OR, = or ( that has nothing after it. Those are the common leftovers.
Why does my EXECUTE IMMEDIATE give ORA-00936 only sometimes?
A variable concatenated into the SQL is NULL in those cases, so part of the statement disappears. Print the string to check, and pass values with bind variables (:d and USING) instead of concatenation.
Does adding WHERE 1=1 change the query result?
It is an always-true condition and does not change the rows returned. In this lab the query with WHERE 1 = 1 returned the same row as the original condition.
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