views:

63

answers:

3

The following simple statement:

INSERT INTO mydb.inventory (itemID) VALUES (:itemID) WHERE playerID = :ID;

Generates the following error:

ORA-00933: SQL command not properly ended

I have tried it without the semi-colon as well as with, but both give me the error. I am certain that the variables are being bound as well.

All my Google searches show that this is usually caused by an ORDER BY clause, but clearly I don't have one. =P

+1  A: 

An insert can not have a where clause. Perhaps you actually meant to update?

Donnie
An insert can have a WHERE clause if using a SELECT to populate the values. See my answer for details.
OMG Ponies
@OMG - Mentally then (to me) the `where` is on the sub-select. But, yes.
Donnie
+3  A: 

You only define a WHERE clause if you are populating the INSERT statement with a SELECT. IE:

INSERT INTO mydb.inventory 
  (itemID)
SELECT :itemID FROM DUAL

Otherwise, you specify the values as-is:

INSERT INTO mydb.inventory 
  (itemID)
VALUES
  (:itemID)

You specify a WHERE clause when you are updating an existing record:

UPDATE mydb.inventory 
   SET itemid = :itemid
 WHERE playerid = :ID
OMG Ponies
+1  A: 

A where clause is rather unusual in an insert statement. Perhaps you're trying to update instead?

UPDATE mydb.inventory SET itemID = :itemID WHERE playerID = :ID;
Andomar
"unusual" is a somewhat understated description of something that is simply syntactically wrong.
Jeffrey Kemp