Common causes
1. A function call missing its closing parenthesis
In COUNT(order_id AS orders the alias ends up inside the call. Close the call before the alias.
SELECT customer_id, COUNT(order_id AS orders FROM orders GROUP BY customer_id;SELECT customer_id, COUNT(order_id) AS orders FROM orders GROUP BY customer_id;2. An IN list that is never closed
Long value lists, often generated or pasted, lose their final ). The next clause (GROUP BY, ORDER BY) is then read as part of the list.
SELECT id FROM orders WHERE status IN ('paid', 'shipped' ORDER BY id;SELECT id FROM orders WHERE status IN ('paid', 'shipped') ORDER BY id;3. A subquery missing its parenthesis
A semicolon or the end of the script inside an open subquery produces “syntax error at end of input” in PostgreSQL. Count the brackets of each nested SELECT.
SELECT name FROM users WHERE id IN (SELECT user_id FROM orders WHERE total > 100;SELECT name FROM users WHERE id IN (SELECT user_id FROM orders WHERE total > 100);4. One closing parenthesis too many
An extra ) gives “Incorrect syntax near ‘)’” in SQL Server and ORA-00933 or ORA-00907 in Oracle. Remove it.
SELECT COUNT(*)) FROM orders;SELECT COUNT(*) FROM orders;Frequently asked questions
Does ORA-00907 always mean a parenthesis is missing?
No. Oracle raises it whenever it expected ) and found something else, for example a misplaced keyword in a column definition (such as NOT NULL before DEFAULT) or an ORDER BY inside an IN subquery. Check that the parentheses balance first, then the syntax inside them.
How do I find the unclosed parenthesis in a long query?
Format it: with one clause per line and nested parts indented, an unclosed bracket stands out. PasteKit refuses to format unbalanced SQL and highlights the bracket that has no partner instead.
Can quotes cause bracket errors?
Yes. An unclosed string hides every bracket after it, which can make balanced SQL look unbalanced. See unterminated quoted strings.