ORA-03049: SQL keyword is not syntactically valid following ...

ORA-03049: SQL keyword 'LIMIT' is not syntactically valid following '...emp ORDER BY salary DESC '

A word appears where Oracle's grammar does not allow anything new to start.

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-13

ORA-03049 is a syntax error introduced in Oracle 23ai. Older versions usually reported the same mistakes as ORA-00933 or similar. The message names the unexpected word and quotes the text just before it, which makes the problem easy to locate.

Despite the wording, the word does not have to be a real keyword. In this lab column names like SALARY and DEPT_ID were also reported as "SQL keyword". Read it as: this word cannot come right after the quoted text.

Causes and fixes

  1. MySQL/PostgreSQL LIMIT after ORDER BY
  2. AND is missing between two WHERE conditions
  3. A comma is missing between columns in UPDATE ... SET
  4. DELETE ... LIMIT n copied from MySQL

1MySQL/PostgreSQL LIMIT after ORDER BY

Oracle has no LIMIT clause. After ORDER BY salary DESC, the word LIMIT is rejected.

Use the standard row-limiting clause: FETCH FIRST 2 ROWS ONLY. It returned the top 2 salaries (Park 6100, Kim 5000). For paging, OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY skipped the first row and returned Kim and Lee.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER, salary NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10, 5000);
INSERT INTO emp VALUES (2, 'Lee', 10, 4200);
INSERT INTO emp VALUES (3, 'Park', 20, 6100);
INSERT INTO emp VALUES (4, 'Choi', 20, 3900);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT name, salary
  FROM emp
 ORDER BY salary DESC
 LIMIT 2;
OUTPUT
 LIMIT 2
 *
ERROR at line 4:
ORA-03049: SQL keyword 'LIMIT' is not syntactically valid following '...emp
ORDER BY salary DESC
'
Help: https://docs.oracle.com/error-help/db/ora-03049/
Checkrun as lab_a
SELECT name, salary
  FROM emp
 ORDER BY salary DESC
 OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY;
OUTPUT
NAME                               SALARY
------------------------------ ----------
Kim                                  5000
Lee                                  4200

2 rows selected.

Without ORDER BY, SELECT ... LIMIT n gives a different error, ORA-03047, because the parser sees LIMIT as a table alias and then trips over the number.

After the fixrun as lab_a
SELECT name, salary
  FROM emp
 ORDER BY salary DESC
 FETCH FIRST 2 ROWS ONLY;
OUTPUT
NAME                               SALARY
------------------------------ ----------
Park                                 6100
Kim                                  5000

2 rows selected.

2AND is missing between two WHERE conditions

WHERE dept_id = 10 followed on the next line by salary >= 4500 has no AND between them. The message quotes ...WHERE dept_id = 10 and names SALARY, the first word of the second condition.

Add AND before the second condition. The query then returned 1 row (Kim).

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER, salary NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10, 5000);
INSERT INTO emp VALUES (2, 'Lee', 10, 4200);
INSERT INTO emp VALUES (3, 'Park', 20, 6100);
INSERT INTO emp VALUES (4, 'Choi', 20, 3900);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT emp_id, name
  FROM emp
 WHERE dept_id = 10
       salary >= 4500;
OUTPUT
       salary >= 4500
       *
ERROR at line 4:
ORA-03049: SQL keyword 'SALARY' is not syntactically valid following '...WHERE dept_id = 10
'
Help: https://docs.oracle.com/error-help/db/ora-03049/
Checkrun as lab_a
SELECT COUNT(*) AS cnt FROM emp WHERE dept_id = 10;
OUTPUT
       CNT
----------
         2

1 row selected.
After the fixrun as lab_a
SELECT emp_id, name
  FROM emp
 WHERE dept_id = 10
   AND salary >= 4500;
OUTPUT
    EMP_ID NAME
---------- ------------------------------
         1 Kim

1 row selected.

3A comma is missing between columns in UPDATE ... SET

In SET name = 'Kim2' followed by dept_id = 20, the comma between the two assignments is missing. Oracle reports DEPT_ID after ...SET name = 'Kim2'.

Put a comma after each assignment except the last. The UPDATE then changed 1 row to Kim2 / 20 (rolled back afterwards in this lab).

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER, salary NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10, 5000);
INSERT INTO emp VALUES (2, 'Lee', 10, 4200);
INSERT INTO emp VALUES (3, 'Park', 20, 6100);
INSERT INTO emp VALUES (4, 'Choi', 20, 3900);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
UPDATE emp
   SET name = 'Kim2'
       dept_id = 20
 WHERE emp_id = 1;
OUTPUT
       dept_id = 20
       *
ERROR at line 3:
ORA-03049: SQL keyword 'DEPT_ID' is not syntactically valid following '...SET name = 'Kim2'
'
Help: https://docs.oracle.com/error-help/db/ora-03049/
Checkrun as lab_a
SELECT emp_id, name, dept_id FROM emp WHERE emp_id = 1;
OUTPUT
    EMP_ID NAME                              DEPT_ID
---------- ------------------------------ ----------
         1 Kim                                    10

1 row selected.
After the fixrun as lab_a
UPDATE emp
   SET name = 'Kim2',
       dept_id = 20
 WHERE emp_id = 1;
SELECT emp_id, name, dept_id FROM emp WHERE emp_id = 1;
ROLLBACK;
OUTPUT
1 row updated.


    EMP_ID NAME                              DEPT_ID
---------- ------------------------------ ----------
         1 Kim2                                   20

1 row selected.


Rollback complete.

4DELETE ... LIMIT n copied from MySQL

MySQL allows DELETE ... LIMIT 1, Oracle does not, so LIMIT is reported after the WHERE condition.

Add AND ROWNUM <= 1 to the WHERE clause instead. One of the two rows in dept 20 was deleted and the count went from 2 to 1.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(20), dept_id NUMBER, salary NUMBER);
INSERT INTO emp VALUES (1, 'Kim', 10, 5000);
INSERT INTO emp VALUES (2, 'Lee', 10, 4200);
INSERT INTO emp VALUES (3, 'Park', 20, 6100);
INSERT INTO emp VALUES (4, 'Choi', 20, 3900);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
DELETE FROM emp
 WHERE dept_id = 20
 LIMIT 1;
OUTPUT
 LIMIT 1
 *
ERROR at line 3:
ORA-03049: SQL keyword 'LIMIT' is not syntactically valid following '...FROM emp
WHERE dept_id = 20
'
Help: https://docs.oracle.com/error-help/db/ora-03049/
Checkrun as lab_a
SELECT COUNT(*) AS cnt FROM emp WHERE dept_id = 20;
OUTPUT
       CNT
----------
         2

1 row selected.

ROWNUM picks whichever rows Oracle reads first, not a specific one. If you need to delete a particular row, use its key in the WHERE clause.

After the fixrun as lab_a
DELETE FROM emp
 WHERE dept_id = 20
   AND ROWNUM <= 1;
SELECT COUNT(*) AS cnt FROM emp WHERE dept_id = 20;
ROLLBACK;
OUTPUT
1 row deleted.


       CNT
----------
         1

1 row selected.


Rollback complete.

FAQ

Does Oracle 23ai support LIMIT?

No. In this 23ai lab both ORDER BY ... LIMIT 2 and DELETE ... LIMIT 1 failed. Use FETCH FIRST n ROWS ONLY for SELECT and ROWNUM <= n for DELETE.

Why does ORA-03049 call my column name a keyword?

The message uses "SQL keyword" for any word the parser did not expect there. Look at the quoted text before it: something like AND or a comma is usually missing at that point.

What is the difference between ORA-03049 and ORA-03048?

Both are 23ai syntax errors. ORA-03049 names a keyword or identifier that cannot come next, ORA-03048 names a reserved word or symbol, such as AS, ORDER or ).

How do I do paging (OFFSET/LIMIT) in Oracle?

ORDER BY ... OFFSET m ROWS FETCH NEXT n ROWS ONLY. In this lab OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY returned rows 2 and 3 of the sorted result.

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

Related errors