Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-18 · container image gvenzl/oracle-free:23-slim
ORA-00907 is raised when Oracle reaches a point where a ) must come next and it finds another word instead. The * under the error line shows where it stopped reading.
The name is a little misleading. Sometimes a bracket really is missing, but sometimes the brackets are balanced and a clause that is not allowed inside them, such as ORDER BY in an IN subquery, triggers the same error. In the lab the causes were an unclosed bracket in a WHERE condition, ORDER BY inside an IN subquery, and a missing ) in CREATE TABLE.
01A bracket in the WHERE condition is never closed
AND (status = 'NEW' OR status = 'PAID' opens a bracket but the query goes straight to ORDER BY, so Oracle stopped at line 3 with ORA-00907.
Deleting the ( makes the error go away, but the result is wrong: without brackets, AND binds before OR, so the query returned 3 orders (100, 101, 102), including order 102 of customer 2. Adding the closing ) returned only customer 1's orders, 100 and 101.
Setup
CREATE TABLE orders (order_id NUMBER, cust_id NUMBER, status VARCHAR2(10));
INSERT INTO orders VALUES (100, 1, 'NEW');
INSERT INTO orders VALUES (101, 1, 'PAID');
INSERT INTO orders VALUES (102, 2, 'PAID');
COMMIT;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT order_id FROM orders
WHERE cust_id = 1
AND (status = 'NEW' OR status = 'PAID'
ORDER BY order_id; AND (status = 'NEW' OR status = 'PAID'
*
ERROR at line 3:
ORA-00907: missing right parenthesis
Help: https://docs.oracle.com/error-help/db/ora-00907/SELECT order_id FROM orders
WHERE cust_id = 1
AND status = 'NEW' OR status = 'PAID'
ORDER BY order_id; ORDER_ID
----------
100
101
102
3 rows selected.Close the bracket in the right place. Do not just delete the opening one: with AND and OR mixed, the brackets change the result.
SELECT order_id FROM orders
WHERE cust_id = 1
AND (status = 'NEW' OR status = 'PAID')
ORDER BY order_id; ORDER_ID
----------
100
101
2 rows selected.02ORDER BY inside an IN subquery
WHERE cust_id IN (SELECT cust_id FROM vip_customers ORDER BY joined) has balanced brackets, yet it failed with ORA-00907. The * points at ORDER BY: Oracle expects the subquery to end there.
The subquery itself runs fine on its own. Removing ORDER BY from the subquery and putting ORDER BY order_id at the end of the outer query returned orders 100 and 102.
Setup
CREATE TABLE orders (order_id NUMBER, cust_id NUMBER);
CREATE TABLE vip_customers (cust_id NUMBER, joined DATE);
INSERT INTO orders VALUES (100, 1);
INSERT INTO orders VALUES (101, 2);
INSERT INTO orders VALUES (102, 3);
INSERT INTO vip_customers VALUES (1, DATE '2026-01-10');
INSERT INTO vip_customers VALUES (3, DATE '2026-03-05');
COMMIT;Table created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Commit complete.SELECT order_id FROM orders
WHERE cust_id IN (SELECT cust_id FROM vip_customers ORDER BY joined);WHERE cust_id IN (SELECT cust_id FROM vip_customers ORDER BY joined)
*
ERROR at line 2:
ORA-00907: missing right parenthesis
Help: https://docs.oracle.com/error-help/db/ora-00907/SELECT cust_id FROM vip_customers ORDER BY joined; CUST_ID
----------
1
3
2 rows selected.Sorting inside an IN subquery has no effect on the result. Sort the outer query instead.
SELECT order_id FROM orders
WHERE cust_id IN (SELECT cust_id FROM vip_customers)
ORDER BY order_id; ORDER_ID
----------
100
102
2 rows selected.03A missing ) in CREATE TABLE
In the CREATE TABLE, the last column was written email VARCHAR2(100;. The (100 is never closed, so ORA-00907 was raised at line 4, and the table was not created (USER_TABLES count was 0).
Writing VARCHAR2(100) and closing the column list with ); created the table with 3 columns.
CREATE TABLE customers (
cust_id NUMBER PRIMARY KEY,
cust_name VARCHAR2(50),
email VARCHAR2(100; email VARCHAR2(100
*
ERROR at line 4:
ORA-00907: missing right parenthesis
Help: https://docs.oracle.com/error-help/db/ora-00907/SELECT COUNT(*) AS cnt FROM user_tables WHERE table_name = 'CUSTOMERS'; CNT
----------
0
1 row selected.Long DDL usually has two brackets at the end: one for the data type size and one for the column list. Check both.
CREATE TABLE customers (
cust_id NUMBER PRIMARY KEY,
cust_name VARCHAR2(50),
email VARCHAR2(100)
);
SELECT column_name, data_length FROM user_tab_columns WHERE table_name = 'CUSTOMERS' ORDER BY column_id;Table created.
COLUMN_NAME DATA_LENGTH
------------------------------ -----------
CUST_ID 22
CUST_NAME 50
EMAIL 100
3 rows selected.FAQ
What does ORA-00907 missing right parenthesis mean?
Oracle expected a ) at the position marked with * but found something else. Either a bracket is not closed, or a clause that is not allowed inside the brackets appears there.
Why do I get ORA-00907 when my parentheses are balanced?
A clause that is not allowed in that place can cause it. In the lab, ORDER BY inside an IN (SELECT ...) subquery raised ORA-00907. Move the ORDER BY to the outer query.
How do I find where ORA-00907 happens?
Look at ERROR at line N and the * under the code in SQL*Plus. That is where Oracle wanted the ). The missing bracket is usually just before it.
Can I just remove the opening parenthesis to fix ORA-00907?
Not when AND and OR are mixed. In the lab, removing it made the query run but it returned an extra row from another customer. Add the ) in the right place instead.
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