How to Fix ORA-00907: Missing Right Parenthesis in Oracle

Use the error position to find where Oracle expected a closing parenthesis, and fix unbalanced lists and subqueries.

ORA-00907 means the parser reached a point where it expected a closing parenthesis and found something else, or the end of the statement. Despite its name, the cause is not always a missing parenthesis: anything Oracle does not expect inside a parenthesized list, such as an unsupported clause in a subquery or a wrong keyword in a column definition, can produce it. The column position in the error points to where parsing stopped.

Reproduce the Error

Example:

select count(*) from dual where 1 in (1, 2;
select * from (select 1 as n from dual order by n desc;

Output:

Error starting at line : 1
In command -
select count(*) from dual where 1 in (1, 2
Error at Command Line : 1 Column : 42
Error report -
SQL Error: ORA-00907: missing right parenthesis

Error starting at line : 2
In command -
select * from (select 1 as n from dual order by n desc
Error at Command Line : 2 Column : 54
Error report -
SQL Error: ORA-00907: missing right parenthesis

Both statements open a parenthesis that is never closed. The Column value in each report, 42 and 54, is the position where the parser expected the closing parenthesis.

Fix: Balance the Parentheses

Example:

select count(*) from dual where 1 in (1, 2);
select * from (select 1 as n from dual order by n desc);

Output:

   COUNT(*)
___________
          1

   N
____
   1

How to Find the Spot

  • Use the column number in the error: count characters from the start of the reported line, or let your editor jump to it.
  • Format the statement with one clause per line and indented subqueries; unbalanced parentheses then stand out.
  • Check what comes right before the reported position: a misplaced keyword or a missing comma inside a list often triggers the same error.

Things to Know

  • In a CREATE TABLE, a wrong data type or a missing comma between column definitions can be reported as ORA-00907 or as a different error, depending on what the parser expected.
  • Many editors highlight matching parentheses; place the cursor on each one to find the one without a partner.
  • In Oracle AI Database 26ai, many syntax mistakes are reported with ORA-03048 or ORA-03049 messages that name the unexpected word, which helps too.

Related Guides

Conclusion

ORA-00907 marks the position where Oracle expected a closing parenthesis. Use the column number to find the spot, balance the parentheses, and look for unexpected keywords inside lists and subqueries.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted