In Oracle database, the following error message may appear when an incorrect SQL statement is used, in SQL Plus or in anywhere that send SQL queries to the databases such as stored procedure or external programs.
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00947: not enough values
The reason for ORA-00947 error is when a SQL statement requires two sets of value, i.e number of number of columns and its value that are specified in the SQL to be equal in number. But the second part of the query which is column values contains fewer items than the first part which is the number of columns. The error may happens in all kind of SQL statements – Insert, Update or Select – and it can also occur in a WHERE or HAVING clause in which a nested sub-SELECT returns too few columns. If the SQL does not specify columns, it means that the values entered are less that the columns existed in the table in database.
For example, the ORA-00947 error will be returned if you try to execute the following SQL statements:
INSERT INTO Customers (Customer_ID, Customer_Name, Birthday) VALUES ('1', 'My Customer');
SELECT * FROM Customers WHERE (Customer_ID, Customer_Name) IN (SELECT Customer_ID FROM Orders);
To solve the error and correct the problem, check that the number of values provided in the column values part is equal that the columns specified, or the number of columns in table, and change the SQL statement to make them equal.
You can either reduce the number of columns, or increase the number of values provided to the column to make the SQL statement equaled. This applies to the nested SQL statements with HAVING or WHERE clause too. For example, the correct SQL statements should be like the following:
INSERT INTO Customers (Customer_ID, Customer_Name, Birthday) VALUES ('1', 'My Customer', '08/08/1988');
INSERT INTO Customers (Customer_ID, Customer_Name) VALUES ('1', 'My Customer');
SELECT * FROM Customers WHERE (Customer_ID, Customer_Name) IN (SELECT Customer_ID, Customer_Name FROM Orders);
SELECT * FROM Customers WHERE (Customer_ID) IN (SELECT Customer_ID FROM Orders);